mirror of
https://github.com/ilyakooo0/reshape.git
synced 2024-11-22 01:09:15 +03:00
Yet more quotes
This commit is contained in:
parent
f70267d069
commit
48e54373ae
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user