dialect/sql: minor changes to allow using Migrate externally (#3316)

This commit is contained in:
Ariel Mashraki
2023-02-14 15:06:36 +02:00
committed by GitHub
parent 4c87e262a6
commit 4e05f76717
2 changed files with 27 additions and 23 deletions

View File

@@ -23,6 +23,13 @@ const (
MaxTypes = math.MaxUint16
)
// NewTypesTable returns a new table for holding the global-id information.
func NewTypesTable() *Table {
return NewTable(TypeTable).
AddPrimary(&Column{Name: "id", Type: field.TypeUint, Increment: true}).
AddColumn(&Column{Name: "type", Type: field.TypeString, Unique: true})
}
// MigrateOption allows configuring Atlas using functional arguments.
type MigrateOption func(*Atlas)
@@ -494,9 +501,7 @@ func (m *Migrate) types(ctx context.Context, tx dialect.ExecQuerier) error {
return err
}
if !exists {
t := NewTable(TypeTable).
AddPrimary(&Column{Name: "id", Type: field.TypeUint, Increment: true}).
AddColumn(&Column{Name: "type", Type: field.TypeString, Unique: true})
t := NewTypesTable()
query, args := m.tBuilder(t).Query()
if err := tx.Exec(ctx, query, args, nil); err != nil {
return fmt.Errorf("create types table: %w", err)