Skip to content

Commit

Permalink
Support citext data type
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 12, 2021
1 parent ea5603d commit 1bc2ed9
Show file tree
Hide file tree
Showing 5 changed files with 2,384 additions and 2,358 deletions.
2 changes: 1 addition & 1 deletion adapter/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (c *column) GetDataType() string {

func (d *PostgresDatabase) getColumns(table string) ([]column, error) {
query := `SELECT s.column_name, s.column_default, s.is_nullable, s.character_maximum_length,
CASE WHEN s.data_type = 'ARRAY' THEN format_type(f.atttypid, f.atttypmod) ELSE s.data_type END,
CASE WHEN s.data_type IN ('ARRAY', 'USER-DEFINED') THEN format_type(f.atttypid, f.atttypmod) ELSE s.data_type END,
CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey,
CASE WHEN pc.contype = 'c' THEN pg_get_constraintdef(pc.oid, true) ELSE NULL END AS check
FROM pg_attribute f
Expand Down
17 changes: 17 additions & 0 deletions cmd/psqldef/psqldef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ func TestPsqldefCreateTableAlterColumn(t *testing.T) {
assertApplyOutput(t, createTable, nothingModified)
}

func TestPsqldefCitextExtension(t *testing.T) {
resetTestDatabase()
mustExecute("psql", "-Upostgres", "psqldef_test", "-c", "CREATE EXTENSION citext;")

createTable := stripHeredoc(`
CREATE TABLE users (
name citext
);
`,
)
assertApplyOutput(t, createTable, applyPrefix+createTable)
assertApplyOutput(t, createTable, nothingModified)

mustExecute("psql", "-Upostgres", "psqldef_test", "-c", "DROP TABLE users;")
mustExecute("psql", "-Upostgres", "psqldef_test", "-c", "DROP EXTENSION citext;")
}

func TestPsqldefIgnoreExtension(t *testing.T) {
resetTestDatabase()
mustExecute("psql", "-Upostgres", "psqldef_test", "-c", "CREATE EXTENSION pg_buffercache;")
Expand Down
Loading

0 comments on commit 1bc2ed9

Please sign in to comment.