Skip to content

Commit 45119c9

Browse files
Update logic
1 parent dac01e9 commit 45119c9

File tree

11 files changed

+40
-50
lines changed

11 files changed

+40
-50
lines changed

internal/migration_acceptance_tests/column_cases_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var columnAcceptanceTestCases = []acceptanceTestCase{
8686
`,
8787
},
8888
expectedHazardTypes: []diff.MigrationHazardType{
89-
diff.MigrationHazardTypeNewNotNullColumnRequiresBackfill,
89+
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
9090
},
9191
},
9292
{

internal/migration_acceptance_tests/database_schema_source_cases_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ var databaseSchemaSourceTestCases = []acceptanceTestCase{
155155
},
156156

157157
expectedHazardTypes: []diff.MigrationHazardType{
158+
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
158159
diff.MigrationHazardTypeIndexBuild,
159-
diff.MigrationHazardTypeNewNotNullColumnRequiresBackfill,
160160
},
161161
expectedDBSchemaDDL: []string{
162162
`

internal/migration_acceptance_tests/foreign_key_constraint_cases_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,6 @@ var foreignKeyConstraintCases = []acceptanceTestCase{
866866

867867
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
868868
diff.MigrationHazardTypeAcquiresShareRowExclusiveLock,
869-
diff.MigrationHazardTypeNewNotNullColumnRequiresBackfill,
870869
diff.MigrationHazardTypeIndexBuild,
871870
diff.MigrationHazardTypeIndexDropped,
872871
},

internal/migration_acceptance_tests/procedure_cases_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ var procedureAcceptanceTestCases = []acceptanceTestCase{
9696
`,
9797
},
9898
expectedHazardTypes: []diff.MigrationHazardType{
99+
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
99100
diff.MigrationHazardTypeHasUntrackableDependencies,
100-
diff.MigrationHazardTypeNewNotNullColumnRequiresBackfill,
101101
},
102102
},
103103
{

internal/migration_acceptance_tests/table_cases_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ var tableAcceptanceTestCases = []acceptanceTestCase{
541541
diff.MigrationHazardTypeAuthzUpdate,
542542
diff.MigrationHazardTypeDeletesData,
543543
diff.MigrationHazardTypeIndexDropped,
544-
diff.MigrationHazardTypeNewNotNullColumnRequiresBackfill,
545544
diff.MigrationHazardTypeIndexBuild,
546545
},
547546
},
@@ -571,7 +570,7 @@ var tableAcceptanceTestCases = []acceptanceTestCase{
571570
},
572571
},
573572
{
574-
name: "Add NOT NULL column without default emits backfill hazard",
573+
name: "Add NOT NULL column without default",
575574
oldSchemaDDL: []string{
576575
`
577576
CREATE TABLE t(
@@ -588,12 +587,7 @@ var tableAcceptanceTestCases = []acceptanceTestCase{
588587
`,
589588
},
590589
expectedHazardTypes: []diff.MigrationHazardType{
591-
diff.MigrationHazardTypeNewNotNullColumnRequiresBackfill,
592-
},
593-
expectedHazardMessages: []string{
594-
"backfill",
595-
"Add the column as NULLABLE",
596-
"SET NOT NULL",
590+
diff.MigrationHazardTypeAcquiresAccessExclusiveLock,
597591
},
598592
},
599593
{

internal/queries/queries.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ WITH identity_col_seq AS (
9090
SELECT
9191
a.attname::TEXT AS column_name,
9292
a.attnotnull AS is_not_null,
93+
a.atthasmissing as has_missing,
9394
a.attlen AS column_size,
9495
a.attidentity::TEXT AS identity_type,
9596
identity_col_seq.seqstart AS start_value,

internal/queries/queries.sql.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/schema/schema.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ type (
274274
// Only populated if IsGenerated is true.
275275
GenerationExpression string
276276
IsNullable bool
277+
// HasMissingValOptimization refers to the 'attmissingval' optimization for adding columns with a default.
278+
HasMissingValOptimization bool
277279
// Size is the number of bytes required to store the value.
278280
// It is used for data-packing purposes
279281
Size int
@@ -980,10 +982,11 @@ func (s *schemaFetcher) buildTable(
980982
}
981983

982984
columns = append(columns, Column{
983-
Name: column.ColumnName,
984-
Type: column.ColumnType,
985-
Collation: collation,
986-
IsNullable: !column.IsNotNull,
985+
Name: column.ColumnName,
986+
Type: column.ColumnType,
987+
Collation: collation,
988+
IsNullable: !column.IsNotNull,
989+
HasMissingValOptimization: column.HasMissing,
987990
// If the column has a default value, this will be a SQL string representing that value.
988991
// Examples:
989992
// ''::text

internal/schema/schema_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ var (
606606
{Name: "content", Type: "text", Default: "''::text", Size: -1, Collation: defaultCollation},
607607
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
608608
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
609-
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
609+
{Name: "version", Type: "integer", IsNullable: false, , Size: 4},
610610
},
611611
CheckConstraints: nil,
612612
ReplicaIdentity: ReplicaIdentityNothing,

pkg/diff/plan.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ import (
1010
type MigrationHazardType = string
1111

1212
const (
13-
MigrationHazardTypeAcquiresAccessExclusiveLock MigrationHazardType = "ACQUIRES_ACCESS_EXCLUSIVE_LOCK"
14-
MigrationHazardTypeAcquiresShareLock MigrationHazardType = "ACQUIRES_SHARE_LOCK"
15-
MigrationHazardTypeAcquiresShareRowExclusiveLock MigrationHazardType = "ACQUIRES_SHARE_ROW_EXCLUSIVE_LOCK"
16-
MigrationHazardTypeCorrectness MigrationHazardType = "CORRECTNESS"
17-
MigrationHazardTypeDeletesData MigrationHazardType = "DELETES_DATA"
18-
MigrationHazardTypeHasUntrackableDependencies MigrationHazardType = "HAS_UNTRACKABLE_DEPENDENCIES"
19-
MigrationHazardTypeIndexBuild MigrationHazardType = "INDEX_BUILD"
20-
MigrationHazardTypeIndexDropped MigrationHazardType = "INDEX_DROPPED"
21-
MigrationHazardTypeImpactsDatabasePerformance MigrationHazardType = "IMPACTS_DATABASE_PERFORMANCE"
22-
MigrationHazardTypeIsUserGenerated MigrationHazardType = "IS_USER_GENERATED"
23-
MigrationHazardTypeExtensionVersionUpgrade MigrationHazardType = "UPGRADING_EXTENSION_VERSION"
24-
MigrationHazardTypeAuthzUpdate MigrationHazardType = "AUTHZ_UPDATE"
25-
MigrationHazardTypeNewNotNullColumnRequiresBackfill MigrationHazardType = "NEW_NOT_NULL_COLUMN_REQUIRES_BACKFILL"
13+
MigrationHazardTypeAcquiresAccessExclusiveLock MigrationHazardType = "ACQUIRES_ACCESS_EXCLUSIVE_LOCK"
14+
MigrationHazardTypeAcquiresShareLock MigrationHazardType = "ACQUIRES_SHARE_LOCK"
15+
MigrationHazardTypeAcquiresShareRowExclusiveLock MigrationHazardType = "ACQUIRES_SHARE_ROW_EXCLUSIVE_LOCK"
16+
MigrationHazardTypeCorrectness MigrationHazardType = "CORRECTNESS"
17+
MigrationHazardTypeDeletesData MigrationHazardType = "DELETES_DATA"
18+
MigrationHazardTypeHasUntrackableDependencies MigrationHazardType = "HAS_UNTRACKABLE_DEPENDENCIES"
19+
MigrationHazardTypeIndexBuild MigrationHazardType = "INDEX_BUILD"
20+
MigrationHazardTypeIndexDropped MigrationHazardType = "INDEX_DROPPED"
21+
MigrationHazardTypeImpactsDatabasePerformance MigrationHazardType = "IMPACTS_DATABASE_PERFORMANCE"
22+
MigrationHazardTypeIsUserGenerated MigrationHazardType = "IS_USER_GENERATED"
23+
MigrationHazardTypeExtensionVersionUpgrade MigrationHazardType = "UPGRADING_EXTENSION_VERSION"
24+
MigrationHazardTypeAuthzUpdate MigrationHazardType = "AUTHZ_UPDATE"
2625
)
2726

2827
// MigrationHazard represents a hazard that a statement poses to a database

0 commit comments

Comments
 (0)