Skip to content

Commit 2216715

Browse files
Treat partitions as not having identity columns
1 parent 45d147a commit 2216715

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

internal/schema/schema.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ func (s *schemaFetcher) buildTable(
865865
}
866866

867867
var identity *ColumnIdentity
868-
if len(column.IdentityType) > 0 {
868+
if len(column.IdentityType) > 0 && table.ParentTableName == "" {
869+
// Exclude identity columns from table partitions because they are owned by the parent.
869870
identity = &ColumnIdentity{
870871
Type: ColumnIdentityType(column.IdentityType),
871872
StartValue: column.StartValue.Int64,

internal/schema/schema_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ var (
469469
content TEXT DEFAULT '',
470470
genre VARCHAR(256) NOT NULL,
471471
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (created_at > CURRENT_TIMESTAMP - interval '1 month'),
472-
version INT NOT NULL DEFAULT 0,
472+
version INT GENERATED ALWAYS AS IDENTITY,
473473
PRIMARY KEY (author, id)
474474
) PARTITION BY LIST (author);
475475
ALTER TABLE foo ADD CONSTRAINT author_check CHECK (author IS NOT NULL AND LENGTH(author) > 0) NOT VALID;
@@ -524,7 +524,7 @@ var (
524524
ALTER TABLE foo_fk_1 ADD CONSTRAINT foo_fk_1_fk FOREIGN KEY (author, content) REFERENCES foo_1 (author, content)
525525
NOT VALID;
526526
`},
527-
expectedHash: "cf473d75363e9f77",
527+
expectedHash: "38588fed86b25fd",
528528
expectedSchema: Schema{
529529
NamedSchemas: []NamedSchema{
530530
{Name: "public"},
@@ -538,7 +538,9 @@ var (
538538
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
539539
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
540540
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
541-
{Name: "version", Type: "integer", Default: "0", Size: 4},
541+
{Name: "version", Type: "integer", Size: 4,
542+
Identity: &ColumnIdentity{Type: "a", MinValue: 1, MaxValue: 2147483647, StartValue: 1, Increment: 1, CacheSize: 1, Cycle: false},
543+
},
542544
},
543545
CheckConstraints: []CheckConstraint{
544546
{Name: "author_check", Expression: "((author IS NOT NULL) AND (length(author) > 0))", IsInheritable: true, KeyColumns: []string{"author"}},
@@ -557,7 +559,7 @@ var (
557559
{Name: "content", Type: "text", Default: "''::text", Size: -1, Collation: defaultCollation},
558560
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
559561
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
560-
{Name: "version", Type: "integer", Default: "0", Size: 4},
562+
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
561563
},
562564
CheckConstraints: nil,
563565
ReplicaIdentity: ReplicaIdentityNothing,
@@ -572,7 +574,7 @@ var (
572574
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
573575
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
574576
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
575-
{Name: "version", Type: "integer", Default: "0", Size: 4},
577+
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
576578
},
577579
CheckConstraints: nil,
578580
ReplicaIdentity: ReplicaIdentityDefault,
@@ -587,7 +589,7 @@ var (
587589
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
588590
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
589591
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
590-
{Name: "version", Type: "integer", Default: "0", Size: 4},
592+
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
591593
},
592594
CheckConstraints: nil,
593595
ReplicaIdentity: ReplicaIdentityDefault,

0 commit comments

Comments
 (0)