-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
45 lines (34 loc) · 952 Bytes
/
schema.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package sqlite
import (
"context"
"github.com/pkg/errors"
"admini.dev/admini/app/lib/database"
"admini.dev/admini/app/lib/schema"
"admini.dev/admini/app/util"
)
func LoadDatabaseSchema(ctx context.Context, db *database.Service, logger util.Logger) (*schema.Schema, error) {
metadata := loadMetadata(db)
tables, err := loadTables(ctx, db, logger)
if err != nil {
return nil, errors.Wrap(err, "can't load tables")
}
err = loadColumns(ctx, tables, db, logger)
if err != nil {
return nil, errors.Wrap(err, "can't load columns")
}
err = loadIndexes(ctx, tables, db, logger)
if err != nil {
return nil, errors.Wrap(err, "can't load indexes")
}
err = loadForeignKeys(ctx, tables, db, logger)
if err != nil {
return nil, errors.Wrap(err, "can't load foreign keys")
}
tables.Sort()
ret := &schema.Schema{
Paths: []string{"postgres:" + db.DatabaseName},
Models: tables,
Metadata: metadata,
}
return ret, nil
}