Skip to content

Commit

Permalink
Better on-disk representations (#206)
Browse files Browse the repository at this point in the history
* Include full function definitions in on-disk representations

* Pretty print constraint definitions

* Use prettier type names for columns

* Test that numeric type precision is represented

* Remove column order from col reps and add them to tables' objreps

* Show diff in README
  • Loading branch information
mzabani authored Dec 20, 2024
1 parent 700f705 commit 4664af3
Show file tree
Hide file tree
Showing 35 changed files with 111 additions and 87 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $ psql -c "SELECT popular_name FROM animals"
$ psql -c "ALTER TABLE animals ALTER COLUMN popular_name TYPE VARCHAR(30)"
ALTER TABLE
$ codd verify-schema
Error: DB and expected schemas do not match. Differing objects and their current DB schemas are: {"schemas/public/tables/animals/cols/popular_name":["different-schemas",{"collation":"default","collation_nsp":"pg_catalog","default":null,"generated":"","hasdefault":false,"identity":"","inhcount":0,"local":true,"notnull":true,"order":2,"privileges":null,"type":"varchar","typmod":34}]}
Error: DB and expected schemas do not match. Differing objects and their current DB schemas are: {"schemas/public/tables/animals/cols/popular_name":["different-schemas",{"collation":"default","collation_nsp":"pg_catalog","default":null,"generated":"","hasdefault":false,"identity":"","inhcount":0,"local":true,"notnull":true,"privileges":null,"type":"character varying(30)"}],"schemas/public/tables/animals/statistics/test_stat_with_expr":["different-schemas",{"definition":"id, popular_name, lower(popular_name::text), (id * 42)","kind":["d","e","f","m"],"owner":"codd_admin"}]}
````

</td>
Expand Down Expand Up @@ -99,6 +99,18 @@ Automatic merge failed; fix conflicts and then commit the result.
</td>
</tr>

<tr>
<td>Useful diffs</td>
<td>

````diff
- "definition": "CHECK (value >= 0::numeric)",
+ "definition": "CHECK (value > 0::numeric)",
````

</td>
</tr>

</table>

¹ Some SQL must run without explicit transactions; single-transaction application only works when none of that is present.
Expand Down
2 changes: 1 addition & 1 deletion expected-schema/schemas/public/routines/floatmultirange;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"argnames": null,
"args": "VARIADIC public.floatrange[]",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "public.floatrange",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "double precision, double precision",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "double precision, double precision, text",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"args": "x time without time zone, y time without time zone",
"config": null,
"definition_md5": "c537e192bed99154c059e7da6626c528",
"definition": "SELECT EXTRACT(EPOCH FROM (x - y))",
"kind": "f",
"lang": "sql",
"leakproof": false,
Expand Down
2 changes: 1 addition & 1 deletion expected-schema/schemas/public/routines/timemultirange;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"argnames": null,
"args": "VARIADIC public.timerange[]",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "public.timerange",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "time without time zone, time without time zone",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"argnames": null,
"args": "time without time zone, time without time zone, text",
"config": null,
"definition_md5": null,
"definition": null,
"kind": "f",
"lang": "internal",
"leakproof": false,
Expand Down
4 changes: 1 addition & 3 deletions expected-schema/schemas/public/tables/animals/cols/id
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 1,
"privileges": null,
"type": "int4",
"typmod": -1
"type": "integer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 2,
"privileges": null,
"type": "text",
"typmod": -1
"type": "text"
}
4 changes: 4 additions & 0 deletions expected-schema/schemas/public/tables/animals/objrep
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"accessmethod": "heap",
"amoptions": null,
"columns_in_order": [
"id",
"popular_name"
],
"compositetype": null,
"forcerowsecurity": false,
"kind": "r",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 1,
"privileges": null,
"type": "int4",
"typmod": -1
"type": "integer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 2,
"privileges": null,
"type": "text",
"typmod": -1
"type": "text"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": false,
"order": 3,
"privileges": null,
"type": "experience",
"typmod": -1
"type": "public.experience"
}
4 changes: 1 addition & 3 deletions expected-schema/schemas/public/tables/employee/cols/surname
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": false,
"order": 4,
"privileges": null,
"type": "text",
"typmod": -1
"type": "text"
}
6 changes: 6 additions & 0 deletions expected-schema/schemas/public/tables/employee/objrep
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"accessmethod": "heap",
"amoptions": null,
"columns_in_order": [
"employee_id",
"employee_name",
"experience",
"surname"
],
"compositetype": null,
"forcerowsecurity": false,
"kind": "r",
Expand Down
1 change: 1 addition & 0 deletions expected-schema/schemas/public/tables/no_cols_table/objrep
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"accessmethod": "heap",
"amoptions": null,
"columns_in_order": [],
"compositetype": null,
"forcerowsecurity": false,
"kind": "r",
Expand Down
1 change: 1 addition & 0 deletions expected-schema/schemas/public/tables/people/objrep
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"accessmethod": "heap",
"amoptions": null,
"columns_in_order": [],
"compositetype": null,
"forcerowsecurity": false,
"kind": "r",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"accessmethod": "heap",
"amoptions": null,
"columns_in_order": [],
"compositetype": null,
"forcerowsecurity": false,
"kind": "r",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 5,
"privileges": null,
"type": "bool",
"typmod": -1
"type": "boolean"
}
4 changes: 1 addition & 3 deletions expected-schema/schemas/public/tables/transactions/cols/id
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 1,
"privileges": null,
"type": "int8",
"typmod": -1
"type": "bigint"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 2,
"privileges": null,
"type": "text",
"typmod": -1
"type": "text"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": true,
"order": 3,
"privileges": null,
"type": "text",
"typmod": -1
"type": "text"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"inhcount": 0,
"local": true,
"notnull": false,
"order": 4,
"privileges": null,
"type": "numeric",
"typmod": 655366
"type": "numeric(10,2)"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"deferrable": false,
"deferred": false,
"definition": "CHECK ((value > (0)::numeric))",
"definition": "CHECK (value > 0::numeric)",
"fk_deltype": " ",
"fk_matchtype": " ",
"fk_ref_table": null,
Expand Down
7 changes: 7 additions & 0 deletions expected-schema/schemas/public/tables/transactions/objrep
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"accessmethod": "heap",
"amoptions": null,
"columns_in_order": [
"id",
"payer",
"receiver",
"value",
"anonymous"
],
"compositetype": null,
"forcerowsecurity": false,
"kind": "r",
Expand Down
2 changes: 1 addition & 1 deletion expected-schema/schemas/public/types/non_empty_text
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"collation_nsp": "pg_catalog",
"comp_type_table": null,
"composite_type_attrs": "",
"constraints": "false;new_constraint;CHECK ((VALUE <> 'empty'::text)) NOT VALID;true;non_empty_text_check;CHECK ((VALUE <> ''::text))",
"constraints": "false;new_constraint;CHECK (VALUE <> 'empty'::text) NOT VALID;true;non_empty_text_check;CHECK (VALUE <> ''::text)",
"default": null,
"delim": ",",
"domain_basetype": "text",
Expand Down
2 changes: 1 addition & 1 deletion expected-schema/schemas/public/types/non_whitespace_text
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"collation_nsp": "pg_catalog",
"comp_type_table": null,
"composite_type_attrs": "",
"constraints": "true;non_whitespace_text_check;CHECK ((TRIM(BOTH FROM VALUE) <> ''::text))",
"constraints": "true;non_whitespace_text_check;CHECK (TRIM(BOTH FROM VALUE) <> ''::text)",
"default": null,
"delim": ",",
"domain_basetype": "text",
Expand Down
Loading

0 comments on commit 4664af3

Please sign in to comment.