-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a check for column default expressions in the electrify() call
- Loading branch information
Showing
16 changed files
with
109 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...electric/lib/electric/postgres/extension/functions/validate_table_column_defaults.sql.eex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- This function validates each column of the table that's being electrified | ||
-- and aborts electrification if any column has DEFAULT expression. | ||
|
||
CREATE OR REPLACE FUNCTION <%= @schema %>.__validate_table_column_defaults(table_name text) | ||
RETURNS VOID AS $function$ | ||
DECLARE | ||
_col_name text; | ||
_col_has_default boolean; | ||
_invalid_cols text[]; | ||
BEGIN | ||
FOR _col_name, _col_has_default IN | ||
SELECT attname, atthasdef | ||
FROM pg_attribute | ||
WHERE attrelid = table_name::regclass AND attnum > 0 AND NOT attisdropped | ||
ORDER BY attnum | ||
LOOP | ||
IF _col_has_default THEN | ||
_invalid_cols = array_append(_invalid_cols, format('%I', _col_name)); | ||
END IF; | ||
END LOOP; | ||
|
||
IF _invalid_cols IS NOT NULL THEN | ||
RAISE EXCEPTION E'Cannot electrify "%" because some of its columns have DEFAULT expression which is not currently supported by Electric:\n %', | ||
table_name, array_to_string(_invalid_cols, E'\n '); | ||
END IF; | ||
END; | ||
$function$ LANGUAGE PLPGSQL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
CREATE TABLE entries ( | ||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id UUID PRIMARY KEY, | ||
content VARCHAR NOT NULL, | ||
content_b TEXT | ||
); | ||
|
||
CREATE TABLE owned_entries ( | ||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), | ||
id UUID PRIMARY KEY, | ||
electric_user_id TEXT NOT NULL, | ||
content VARCHAR NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.