-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql/mssql: initial diff and migrate (#1783)
- Loading branch information
Showing
4 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2021-present The Atlas Authors. All rights reserved. | ||
// This source code is licensed under the Apache 2.0 license found | ||
// in the LICENSE file in the root directory of this source tree. | ||
|
||
package mssql | ||
|
||
import ( | ||
"ariga.io/atlas/sql/internal/sqlx" | ||
"ariga.io/atlas/sql/schema" | ||
) | ||
|
||
// DefaultDiff provides basic diffing capabilities for MS-SQL dialects. | ||
// Note, it is recommended to call Open, create a new Driver and use its Differ | ||
// when a database connection is available. | ||
var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{}} | ||
|
||
// A diff provides a MS-SQL implementation for sqlx.DiffDriver. | ||
type diff struct{ conn } | ||
|
||
// SchemaAttrDiff returns a changeset for migrating schema attributes from one state to the other. | ||
func (d *diff) SchemaAttrDiff(_, _ *schema.Schema) []schema.Change { | ||
// No special schema attribute diffing for MS-SQL. | ||
return nil | ||
} | ||
|
||
// TableAttrDiff returns a changeset for migrating table attributes from one state to the other. | ||
func (d *diff) TableAttrDiff(_, _ *schema.Table) ([]schema.Change, error) { | ||
// Not implemented yet. | ||
return nil, nil | ||
} | ||
|
||
// ColumnChange returns the schema changes (if any) for migrating one column to the other. | ||
func (d *diff) ColumnChange(_ *schema.Table, _, _ *schema.Column) (schema.ChangeKind, error) { | ||
// Not implemented yet. | ||
return schema.NoChange, nil | ||
} | ||
|
||
// IsGeneratedIndexName reports if the index name was generated by the database. | ||
func (d *diff) IsGeneratedIndexName(_ *schema.Table, _ *schema.Index) bool { | ||
// Not implemented yet. | ||
return false | ||
} | ||
|
||
// IndexAttrChanged reports if the index attributes were changed. | ||
// The default type is BTREE if no type was specified. | ||
func (*diff) IndexAttrChanged(_, _ []schema.Attr) bool { | ||
// Not implemented yet. | ||
return false | ||
} | ||
|
||
// IndexPartAttrChanged reports if the index-part attributes were changed. | ||
func (*diff) IndexPartAttrChanged(_, _ *schema.Index, _ int) bool { | ||
// Not implemented yet. | ||
return false | ||
} | ||
|
||
// ReferenceChanged reports if the foreign key referential action was changed. | ||
func (*diff) ReferenceChanged(_, _ schema.ReferenceOption) bool { | ||
// Not implemented yet. | ||
return false | ||
} | ||
|
||
// AnnotateChanges implements the sqlx.ChangeAnnotator interface. | ||
func (*diff) AnnotateChanges(_ []schema.Change, _ *schema.DiffOptions) error { | ||
// Not implemented yet. | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2021-present The Atlas Authors. All rights reserved. | ||
// This source code is licensed under the Apache 2.0 license found | ||
// in the LICENSE file in the root directory of this source tree. | ||
|
||
package mssql | ||
|
||
import ( | ||
"context" | ||
|
||
"ariga.io/atlas/sql/internal/sqlx" | ||
"ariga.io/atlas/sql/migrate" | ||
"ariga.io/atlas/sql/schema" | ||
) | ||
|
||
// DefaultPlan provides basic planning capabilities for MS-SQL dialects. | ||
// Note, it is recommended to call Open, create a new Driver and use its | ||
// migrate.PlanApplier when a database connection is available. | ||
var DefaultPlan migrate.PlanApplier = &planApply{conn: conn{ExecQuerier: sqlx.NoRows}} | ||
|
||
// A planApply provides migration capabilities for schema elements. | ||
type planApply struct{ conn } | ||
|
||
// ApplyChanges applies the changes on the database. An error is returned | ||
// if the driver is unable to produce a plan to do so, or one of the statements | ||
// is failed or unsupported. | ||
func (p *planApply) ApplyChanges(ctx context.Context, changes []schema.Change, opts ...migrate.PlanOption) error { | ||
return sqlx.ApplyChanges(ctx, changes, p, opts...) | ||
} | ||
|
||
// PlanChanges returns a migration plan for the given schema changes. | ||
func (p *planApply) PlanChanges(_ context.Context, _ string, _ []schema.Change, _ ...migrate.PlanOption) (*migrate.Plan, error) { | ||
// Not implemented yet. | ||
return nil, nil | ||
} |