Skip to content

Commit

Permalink
Merge pull request #3532 from ebean-orm/feature/sql-play-ebean
Browse files Browse the repository at this point in the history
#3408 play-ebean inline sql comment in test generated scripts
  • Loading branch information
rbygrave authored Dec 20, 2024
2 parents 4367546 + 3fea5ce commit 18e6374
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ delimiter $$
--
CREATE OR REPLACE PROCEDURE usp_ebean_drop_foreign_keys(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256))
AS
-- play-ebean-start
BEGIN
DECLARE foreign_key_names TABLE(CONSTRAINT_NAME NVARCHAR(256), TABLE_NAME NVARCHAR(256));
DECLARE i INT;
Expand All @@ -17,6 +18,7 @@ EXEC 'ALTER TABLE "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.TABLE_NAME[i]) |
END FOR;

END;
-- play-ebean-end
$$

delimiter $$
Expand All @@ -26,8 +28,10 @@ delimiter $$
--
CREATE OR REPLACE PROCEDURE usp_ebean_drop_column(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256))
AS
-- play-ebean-start
BEGIN
CALL usp_ebean_drop_foreign_keys(table_name, column_name);
EXEC 'ALTER TABLE "' || UPPER(ESCAPE_DOUBLE_QUOTES(table_name)) || '" DROP ("' || UPPER(ESCAPE_DOUBLE_QUOTES(column_name)) || '")';
END;
-- play-ebean-end
$$
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-745347271, I__create_procs.sql
1349158244, I__create_procs.sql
-2017770851, 1.0__initial.sql
-475843596, 1.1.sql
1535221752, 1.2__dropsFor_1.1.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ delimiter $$
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
--
CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
-- play-ebean-start
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE c_fk_name CHAR(255);
Expand All @@ -29,6 +30,7 @@ END LOOP;

CLOSE curs;
END
-- play-ebean-end
$$

DROP PROCEDURE IF EXISTS usp_ebean_drop_column;
Expand All @@ -39,10 +41,12 @@ delimiter $$
-- deletes the column and ensures that all indices and constraints are dropped first
--
CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
-- play-ebean-start
BEGIN
CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name);
SET @sql = CONCAT('ALTER TABLE `', p_table_name, '` DROP COLUMN `', p_column_name, '`');
PREPARE stmt FROM @sql;
EXECUTE stmt;
END
-- play-ebean-end
$$
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-1933396282, I__create_procs.sql
-1617676189, I__create_procs.sql
-2111548334, 1.0__initial.sql
1085383251, 1.1.sql
1187950993, 1.2__dropsFor_1.1.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ delimiter $$
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
--
CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
-- play-ebean-start
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE c_fk_name CHAR(255);
Expand All @@ -29,6 +30,7 @@ END LOOP;

CLOSE curs;
END
-- play-ebean-end
$$

DROP PROCEDURE IF EXISTS usp_ebean_drop_column;
Expand All @@ -39,10 +41,12 @@ delimiter $$
-- deletes the column and ensures that all indices and constraints are dropped first
--
CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
-- play-ebean-start
BEGIN
CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name);
SET @sql = CONCAT('ALTER TABLE `', p_table_name, '` DROP COLUMN `', p_column_name, '`');
PREPARE stmt FROM @sql;
EXECUTE stmt;
END
-- play-ebean-end
$$
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-1933396282, I__create_procs.sql
-1617676189, I__create_procs.sql
1980830787, 1.0__initial.sql
-151422898, 1.1.sql
-1097227916, 1.2__dropsFor_1.1.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ delimiter $$
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
--
CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
-- play-ebean-start
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE c_fk_name CHAR(255);
Expand All @@ -29,6 +30,7 @@ END LOOP;

CLOSE curs;
END
-- play-ebean-end
$$

DROP PROCEDURE IF EXISTS usp_ebean_drop_column;
Expand All @@ -39,10 +41,12 @@ delimiter $$
-- deletes the column and ensures that all indices and constraints are dropped first
--
CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
-- play-ebean-start
BEGIN
CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name);
SET @sql = CONCAT('ALTER TABLE `', p_table_name, '` DROP COLUMN `', p_column_name, '`');
PREPARE stmt FROM @sql;
EXECUTE stmt;
END
-- play-ebean-end
$$
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-1933396282, I__create_procs.sql
-1617676189, I__create_procs.sql
369577572, 1.0__initial.sql
-151422898, 1.1.sql
-1097227916, 1.2__dropsFor_1.1.sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ alter table migtest_e_history6 add column if not exists sys_period tstzrange not
create table migtest_e_history2_history(like migtest_e_history2);
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
create or replace function migtest_e_history2_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -213,6 +214,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history2_history_upd
Expand All @@ -223,6 +225,7 @@ create trigger migtest_e_history2_history_upd
create table migtest_e_history3_history(like migtest_e_history3);
create view migtest_e_history3_with_history as select * from migtest_e_history3 union all select * from migtest_e_history3_history;
create or replace function migtest_e_history3_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -238,6 +241,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history3_history_upd
Expand All @@ -248,6 +252,7 @@ create trigger migtest_e_history3_history_upd
create table migtest_e_history4_history(like migtest_e_history4);
create view migtest_e_history4_with_history as select * from migtest_e_history4 union all select * from migtest_e_history4_history;
create or replace function migtest_e_history4_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -263,6 +268,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history4_history_upd
Expand All @@ -273,6 +279,7 @@ create trigger migtest_e_history4_history_upd
create table migtest_e_history5_history(like migtest_e_history5);
create view migtest_e_history5_with_history as select * from migtest_e_history5 union all select * from migtest_e_history5_history;
create or replace function migtest_e_history5_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -288,6 +295,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history5_history_upd
Expand All @@ -298,6 +306,7 @@ create trigger migtest_e_history5_history_upd
create table migtest_e_history6_history(like migtest_e_history6);
create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history;
create or replace function migtest_e_history6_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -313,6 +322,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history6_history_upd
Expand All @@ -323,6 +333,7 @@ create trigger migtest_e_history6_history_upd
create table table_history(like "table");
create view table_with_history as select * from "table" union all select * from table_history;
create or replace function table_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -338,6 +349,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger table_history_upd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest5 unique
create table migtest_e_history_history(like migtest_e_history);
create view migtest_e_history_with_history as select * from migtest_e_history union all select * from migtest_e_history_history;
create or replace function migtest_e_history_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -270,6 +271,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history_history_upd
Expand All @@ -281,6 +283,7 @@ comment on column migtest_e_history.test_string is 'Column altered to long now';
comment on table migtest_e_history is 'We have history now';
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
create or replace function migtest_e_history2_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -296,6 +299,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history2_history_upd
Expand All @@ -304,6 +308,7 @@ create trigger migtest_e_history2_history_upd

create view migtest_e_history3_with_history as select * from migtest_e_history3 union all select * from migtest_e_history3_history;
create or replace function migtest_e_history3_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -319,6 +324,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history3_history_upd
Expand All @@ -327,6 +333,7 @@ create trigger migtest_e_history3_history_upd

create view migtest_e_history4_with_history as select * from migtest_e_history4 union all select * from migtest_e_history4_history;
create or replace function migtest_e_history4_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -342,6 +349,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history4_history_upd
Expand All @@ -350,6 +358,7 @@ create trigger migtest_e_history4_history_upd

create view migtest_e_history5_with_history as select * from migtest_e_history5 union all select * from migtest_e_history5_history;
create or replace function migtest_e_history5_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -365,6 +374,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history5_history_upd
Expand All @@ -373,6 +383,7 @@ create trigger migtest_e_history5_history_upd

create view migtest_e_history6_with_history as select * from migtest_e_history6 union all select * from migtest_e_history6_history;
create or replace function migtest_e_history6_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -388,6 +399,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history6_history_upd
Expand All @@ -397,6 +409,7 @@ create trigger migtest_e_history6_history_upd
comment on column "table"."index" is 'this is an other comment';
create view table_with_history as select * from "table" union all select * from table_history;
create or replace function table_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -412,6 +425,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger table_history_upd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ alter table migtest_e_history2_history drop column obsolete_string2;
-- apply post alter
create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;
create or replace function migtest_e_history2_history_version() returns trigger as $$
-- play-ebean-start
declare
lowerTs timestamptz;
upperTs timestamptz;
Expand All @@ -31,6 +32,7 @@ begin
return old;
end if;
end;
-- play-ebean-end
$$ LANGUAGE plpgsql;

create trigger migtest_e_history2_history_upd
Expand Down
Loading

0 comments on commit 18e6374

Please sign in to comment.