Skip to content

Commit

Permalink
Treat partitions as not having identity columns
Browse files Browse the repository at this point in the history
  • Loading branch information
bplunkett-stripe committed Dec 11, 2024
1 parent 45d147a commit 2216715
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ func (s *schemaFetcher) buildTable(
}

var identity *ColumnIdentity
if len(column.IdentityType) > 0 {
if len(column.IdentityType) > 0 && table.ParentTableName == "" {
// Exclude identity columns from table partitions because they are owned by the parent.
identity = &ColumnIdentity{
Type: ColumnIdentityType(column.IdentityType),
StartValue: column.StartValue.Int64,
Expand Down
14 changes: 8 additions & 6 deletions internal/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ var (
content TEXT DEFAULT '',
genre VARCHAR(256) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (created_at > CURRENT_TIMESTAMP - interval '1 month'),
version INT NOT NULL DEFAULT 0,
version INT GENERATED ALWAYS AS IDENTITY,
PRIMARY KEY (author, id)
) PARTITION BY LIST (author);
ALTER TABLE foo ADD CONSTRAINT author_check CHECK (author IS NOT NULL AND LENGTH(author) > 0) NOT VALID;
Expand Down Expand Up @@ -524,7 +524,7 @@ var (
ALTER TABLE foo_fk_1 ADD CONSTRAINT foo_fk_1_fk FOREIGN KEY (author, content) REFERENCES foo_1 (author, content)
NOT VALID;
`},
expectedHash: "cf473d75363e9f77",
expectedHash: "38588fed86b25fd",
expectedSchema: Schema{
NamedSchemas: []NamedSchema{
{Name: "public"},
Expand All @@ -538,7 +538,9 @@ var (
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
{Name: "version", Type: "integer", Default: "0", Size: 4},
{Name: "version", Type: "integer", Size: 4,
Identity: &ColumnIdentity{Type: "a", MinValue: 1, MaxValue: 2147483647, StartValue: 1, Increment: 1, CacheSize: 1, Cycle: false},
},
},
CheckConstraints: []CheckConstraint{
{Name: "author_check", Expression: "((author IS NOT NULL) AND (length(author) > 0))", IsInheritable: true, KeyColumns: []string{"author"}},
Expand All @@ -557,7 +559,7 @@ var (
{Name: "content", Type: "text", Default: "''::text", Size: -1, Collation: defaultCollation},
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
{Name: "version", Type: "integer", Default: "0", Size: 4},
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
},
CheckConstraints: nil,
ReplicaIdentity: ReplicaIdentityNothing,
Expand All @@ -572,7 +574,7 @@ var (
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
{Name: "version", Type: "integer", Default: "0", Size: 4},
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
},
CheckConstraints: nil,
ReplicaIdentity: ReplicaIdentityDefault,
Expand All @@ -587,7 +589,7 @@ var (
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
{Name: "version", Type: "integer", Default: "0", Size: 4},
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
},
CheckConstraints: nil,
ReplicaIdentity: ReplicaIdentityDefault,
Expand Down

0 comments on commit 2216715

Please sign in to comment.