Skip to content

Commit

Permalink
Fall back to raw SQL for STORAGE options
Browse files Browse the repository at this point in the history
Column storage options are not representable by `pgroll` `Column`
definitions.
  • Loading branch information
andrew-farries committed Dec 18, 2024
1 parent fc83197 commit 2566338
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/sql2pgroll/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func convertCreateStmt(stmt *pgq.CreateStmt) (migrations.Operations, error) {
if err != nil {
return nil, fmt.Errorf("error converting column definition: %w", err)
}
if column == nil {
return nil, nil
}
columns = append(columns, *column)
default:
return nil, nil
Expand Down Expand Up @@ -80,6 +83,10 @@ func canConvertCreateStatement(stmt *pgq.CreateStmt) bool {
}

func convertColumnDef(col *pgq.ColumnDef) (*migrations.Column, error) {
if !canConvertColumnDef(col) {
return nil, nil
}

// Convert the column type
typeString, err := pgq.DeparseTypeName(col.TypeName)
if err != nil {
Expand Down Expand Up @@ -111,3 +118,14 @@ func convertColumnDef(col *pgq.ColumnDef) (*migrations.Column, error) {
Pk: pk,
}, nil
}

// canConvertColumnDef returns true iff `col` can be converted to a pgroll
// `Column` definition.
func canConvertColumnDef(col *pgq.ColumnDef) bool {
// Column storage options are not supported
if col.GetStorageName() != "" {
return false
}

return true
}
3 changes: 3 additions & 0 deletions pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func TestUnconvertableCreateTableStatements(t *testing.T) {
// The LIKE clause is not supported
"CREATE TABLE foo(a int, LIKE bar)",
"CREATE TABLE foo(LIKE bar)",

// column `STORAGE` options are not supported
"CREATE TABLE foo(a int STORAGE PLAIN)",
}

for _, sql := range tests {
Expand Down

0 comments on commit 2566338

Please sign in to comment.