Add Schema definition changes to support the linter functions
Some checks failed
CI / release-test (push) Failing after 16s
Some checks failed
CI / release-test (push) Failing after 16s
This commit is contained in:
@@ -2,6 +2,8 @@ package schema
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/jinzhu/inflection"
|
||||
@@ -22,6 +24,14 @@ func InitDB(sql_schema string) *sqlx.DB {
|
||||
return db
|
||||
}
|
||||
|
||||
func SchemaFromSQLFile(filepath string) (Schema, error) {
|
||||
sqlBytes, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
return Schema{}, fmt.Errorf("failed to read SQL file: %w", err)
|
||||
}
|
||||
return SchemaFromDB(InitDB(string(sqlBytes))), nil
|
||||
}
|
||||
|
||||
// SchemaFromDB takes a DB connection, checks its schema metadata tables, and returns a Schema.
|
||||
func SchemaFromDB(db *sqlx.DB) Schema {
|
||||
ret := Schema{Tables: map[string]Table{}, Indexes: map[string]Index{}}
|
||||
|
||||
Reference in New Issue
Block a user