From 48e54373ae0ceeadf976c156ae6d0f2fe30c5d16 Mon Sep 17 00:00:00 2001 From: iko Date: Fri, 18 Oct 2024 14:17:14 +0300 Subject: [PATCH] Yet more quotes --- src/migrations/add_column.rs | 12 ++++++------ src/migrations/alter_column.rs | 14 +++++++------- src/migrations/remove_column.rs | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/migrations/add_column.rs b/src/migrations/add_column.rs index 6ebf625..a78b6be 100644 --- a/src/migrations/add_column.rs +++ b/src/migrations/add_column.rs @@ -124,7 +124,7 @@ impl Action for AddColumn { // Add triggers to fill in values as they are inserted/updated let query = format!( r#" - CREATE OR REPLACE FUNCTION {trigger_name}() + CREATE OR REPLACE FUNCTION "{trigger_name}"() RETURNS TRIGGER AS $$ BEGIN IF NOT reshape.is_new_schema() THEN @@ -139,7 +139,7 @@ impl Action for AddColumn { $$ language 'plpgsql'; DROP TRIGGER IF EXISTS "{trigger_name}" ON "{table}"; - CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{table}" FOR EACH ROW EXECUTE PROCEDURE {trigger_name}(); + CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{table}" FOR EACH ROW EXECUTE PROCEDURE "{trigger_name}"(); "#, temp_column_name = temp_column_name, trigger_name = self.trigger_name(ctx), @@ -183,7 +183,7 @@ impl Action for AddColumn { // Add triggers to fill in values as they are inserted/updated let query = format!( r#" - CREATE OR REPLACE FUNCTION {trigger_name}() + CREATE OR REPLACE FUNCTION "{trigger_name}"() RETURNS TRIGGER AS $$ #variable_conflict use_variable BEGIN @@ -208,7 +208,7 @@ impl Action for AddColumn { $$ language 'plpgsql'; DROP TRIGGER IF EXISTS "{trigger_name}" ON "{from_table_real}"; - CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{from_table_real}" FOR EACH ROW EXECUTE PROCEDURE {trigger_name}(); + CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{from_table_real}" FOR EACH ROW EXECUTE PROCEDURE "{trigger_name}"(); "#, assignments = from_table_assignments.join("\n"), changed_table_real = table.real_name, @@ -243,7 +243,7 @@ impl Action for AddColumn { // Add triggers to fill in values as they are inserted/updated let query = format!( r#" - CREATE OR REPLACE FUNCTION {trigger_name}() + CREATE OR REPLACE FUNCTION "{trigger_name}"() RETURNS TRIGGER AS $$ #variable_conflict use_variable BEGIN @@ -272,7 +272,7 @@ impl Action for AddColumn { $$ language 'plpgsql'; DROP TRIGGER IF EXISTS "{trigger_name}" ON "{changed_table_real}"; - CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{changed_table_real}" FOR EACH ROW EXECUTE PROCEDURE {trigger_name}(); + CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{changed_table_real}" FOR EACH ROW EXECUTE PROCEDURE "{trigger_name}"(); "#, changed_table_assignments = changed_table_assignments.join("\n"), changed_table_real = table.real_name, diff --git a/src/migrations/alter_column.rs b/src/migrations/alter_column.rs index fb30594..fec8475 100644 --- a/src/migrations/alter_column.rs +++ b/src/migrations/alter_column.rs @@ -100,13 +100,13 @@ impl Action for AlterColumn { let query = format!( r#" - CREATE OR REPLACE FUNCTION {up_trigger}() + CREATE OR REPLACE FUNCTION "{up_trigger}"() RETURNS TRIGGER AS $$ BEGIN IF NOT reshape.is_new_schema() THEN DECLARE {declarations} - {existing_column} public.{table}.{existing_column_real}%TYPE := NEW.{existing_column_real}; + {existing_column} public."{table}"."{existing_column_real}"%TYPE := NEW.{existing_column_real}; BEGIN NEW.{temp_column} = {up}; END; @@ -116,17 +116,17 @@ impl Action for AlterColumn { $$ language 'plpgsql'; DROP TRIGGER IF EXISTS "{up_trigger}" ON "{table}"; - CREATE TRIGGER "{up_trigger}" BEFORE INSERT OR UPDATE ON "{table}" FOR EACH ROW EXECUTE PROCEDURE {up_trigger}(); + CREATE TRIGGER "{up_trigger}" BEFORE INSERT OR UPDATE ON "{table}" FOR EACH ROW EXECUTE PROCEDURE "{up_trigger}"(); - CREATE OR REPLACE FUNCTION {down_trigger}() + CREATE OR REPLACE FUNCTION "{down_trigger}"() RETURNS TRIGGER AS $$ BEGIN IF reshape.is_new_schema() THEN DECLARE {declarations} - {existing_column} public.{table}.{temp_column}%TYPE := NEW.{temp_column}; + {existing_column} public."{table}"."{temp_column}"%TYPE := NEW."{temp_column}"; BEGIN - NEW.{existing_column_real} = {down}; + NEW."{existing_column_real}" = {down}; END; END IF; RETURN NEW; @@ -134,7 +134,7 @@ impl Action for AlterColumn { $$ language 'plpgsql'; DROP TRIGGER IF EXISTS "{down_trigger}" ON "{table}"; - CREATE TRIGGER "{down_trigger}" BEFORE INSERT OR UPDATE ON "{table}" FOR EACH ROW EXECUTE PROCEDURE {down_trigger}(); + CREATE TRIGGER "{down_trigger}" BEFORE INSERT OR UPDATE ON "{table}" FOR EACH ROW EXECUTE PROCEDURE "{down_trigger}"(); "#, existing_column = &self.column, existing_column_real = column.real_name, diff --git a/src/migrations/remove_column.rs b/src/migrations/remove_column.rs index 55a92fc..39d8910 100644 --- a/src/migrations/remove_column.rs +++ b/src/migrations/remove_column.rs @@ -100,7 +100,7 @@ impl Action for RemoveColumn { if let Transformation::Simple(down) = down { let query = format!( r#" - CREATE OR REPLACE FUNCTION {trigger_name}() + CREATE OR REPLACE FUNCTION "{trigger_name}"() RETURNS TRIGGER AS $$ BEGIN IF reshape.is_new_schema() THEN @@ -115,7 +115,7 @@ impl Action for RemoveColumn { $$ language 'plpgsql'; DROP TRIGGER IF EXISTS "{trigger_name}" ON "{table}"; - CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{table}" FOR EACH ROW EXECUTE PROCEDURE {trigger_name}(); + CREATE TRIGGER "{trigger_name}" BEFORE UPDATE OR INSERT ON "{table}" FOR EACH ROW EXECUTE PROCEDURE "{trigger_name}"(); "#, column_name = self.column, trigger_name = self.trigger_name(ctx), @@ -146,7 +146,7 @@ impl Action for RemoveColumn { // NOT NULL is not checked at the end of a transaction, but immediately upon update. let query = format!( r#" - CREATE OR REPLACE FUNCTION {trigger_name}() + CREATE OR REPLACE FUNCTION "{trigger_name}"() RETURNS TRIGGER AS $$ BEGIN IF NOT reshape.is_new_schema() THEN @@ -164,7 +164,7 @@ impl Action for RemoveColumn { AFTER INSERT OR UPDATE ON "{table}" FOR EACH ROW - EXECUTE PROCEDURE {trigger_name}(); + EXECUTE PROCEDURE "{trigger_name}"(); "#, table = self.table, trigger_name = self.not_null_constraint_trigger_name(ctx),