-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(electric): Clean up templated SQL routines #511
Conversation
ff0c722
to
1a93b31
Compare
34d5a5b
to
065abdd
Compare
1a93b31
to
d7217db
Compare
7ce86cc
to
9a7f2b8
Compare
9a7f2b8
to
74a5da9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😓 thanks for the hard work on this one! good changes all in all, but I do question the need for the functions-as-functions approach considering the required lifetime of these blobs of rendered sql.
components/electric/lib/electric/postgres/extension/functions.ex
Outdated
Show resolved
Hide resolved
7fa9214
to
a4eab72
Compare
70b4700
to
d81b331
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lovely stuff. Shame git didn't track the renames.
@@ -19,11 +19,6 @@ defmodule Electric.Postgres.Extension.Migrations.Migration_20230512000000_confli | |||
def up(schema) do | |||
[ | |||
@contents["electric_tag_type_and_operators"], | |||
@contents["utility_functions"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing that this is ok and referencing functions that don't exist is not a problem -- if so then good to get rid of the duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the context. If you have a function that calls another function, it is fine for the former to be defined before the latter.
On the other hand, if you have a trigger definition that references a function, the function has to be defined prior to the evaluation of the trigger def.
The functions/procedures are now defined at run time.
Log sample: 00:43:08.719 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'capture_ddl.sql.eex' 00:43:08.720 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'current_transaction_id.sql.eex' 00:43:08.720 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'current_xact_id.sql.eex' 00:43:08.721 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'current_xact_ts.sql.eex' 00:43:08.723 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'ddlx/assign.sql.eex' 00:43:08.724 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'ddlx/disable.sql.eex' 00:43:08.725 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'ddlx/enable.sql.eex' 00:43:08.725 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'ddlx/grant.sql.eex' 00:43:08.726 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'ddlx/unassign.sql.eex' 00:43:08.727 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'electrify.sql.eex' 00:43:08.728 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'electrify/__validate_table_column_defaults.sql.eex' 00:43:08.728 pid=<0.1285.0> origin=postgres_1 [debug] Successfully (re)defined SQL routine from 'electrify/__validate_table_column_types.sql.eex' 00:45:22.624 pid=<0.1285.0> origin=postgres_1 [error] initialization for postgresql failed with reason: {:rollback, %RuntimeError{message: "Failed to define SQL routine from 'electrify.sql.eex' with error: {:error, {:error, :error, \"42601\", :syntax_error, \"syntax error at or near \\\"SELECD\\\"\", [file: \"scan.l\", line: \"1176\", position: \"243\", routine: \"scanner_yyerror\", severity: \"ERROR\"]}}"}}
...so that they are available in the packaged Elixir release to be loaded and evaluated at run time.
d81b331
to
1b10be8
Compare
This is a cleanup PR that includes the following changes: * Remove some of the dead SQL code from Extension migration modules. The code used to define routines but they are now defined at run time. * Import the Extension module into Functions to make all functions from the former available automatically to all templated SQL routines. This removes the need to maintain a map of assigns by hand. * Fix the wildcard pattern in Functions to include subdirectories. Prior to this change, the functions from `lib/electric/postgres/extension/functions/ddlx/` weren't included in the module.
This is a cleanup PR that includes the following changes:
lib/electric/postgres/extension/functions/ddlx/
weren't included in the module.