Skip to content

Commit 1c038f4

Browse files
authored
Merge pull request #3408 from mkurz/meta_datastored-procedures-DDL
Add metadata to stored procedures for 3rd party libs
2 parents 49b6f3d + e99f922 commit 1c038f4

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/ddlgeneration/platform/PostgresHistoryDdl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ protected void createOrReplaceFunction(DdlBuffer apply, String procedureName, St
7171
apply
7272
.append("create or replace function ").append(procedureName).append("() returns trigger as $$").newLine();
7373

74+
apply.append("-- play-ebean-start").newLine();
75+
7476
apply.append("declare").newLine()
7577
.append(" lowerTs timestamptz;").newLine()
7678
.append(" upperTs timestamptz;").newLine();
@@ -93,6 +95,7 @@ protected void createOrReplaceFunction(DdlBuffer apply, String procedureName, St
9395
apply
9496
.append(" end if;").newLine()
9597
.append("end;").newLine()
98+
.append("-- play-ebean-end").newLine()
9699
.append("$$ LANGUAGE plpgsql;").newLine();
97100

98101
apply.end();

ebean-ddl-generator/src/main/resources/io/ebeaninternal/dbmigration/builtin-extra-ddl-partitioning.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
-- Type used to hold common partitioning parameters such as period start and end etc
1111
------------------------------------------------------------------------------------
1212
do $$
13+
-- play-ebean-start
1314
begin
1415
if not exists (select 1 from pg_type where typname = 'partition_meta') THEN
1516
create type partition_meta as
@@ -22,7 +23,9 @@ begin
2223
part_name text
2324
);
2425
end if;
25-
end$$;
26+
end;
27+
-- play-ebean-end
28+
$$;
2629

2730
------------------------------------------------------------------------------------
2831
-- Function: _partition_create
@@ -34,6 +37,7 @@ create or replace function _partition_create(meta partition_meta)
3437
language plpgsql
3538
set timezone to 'UTC'
3639
as $$
40+
-- play-ebean-start
3741
begin
3842
if (meta.schema_name = '') then
3943
execute format('create table if not exists %I partition of %I for values from (''%s'') TO (''%s'')', meta.part_name, meta.base_name, meta.period_start, meta.period_end);
@@ -42,6 +46,7 @@ begin
4246
end if;
4347
return meta.part_name;
4448
end;
49+
-- play-ebean-end
4550
$$;
4651

4752

@@ -60,6 +65,7 @@ create or replace function _partition_meta(
6065
language plpgsql
6166
set timezone to 'UTC'
6267
as $$
68+
-- play-ebean-start
6369
declare
6470
partName text;
6571
meta partition_meta;
@@ -92,6 +98,7 @@ begin
9298

9399
return meta;
94100
end;
101+
-- play-ebean-end
95102
$$;
96103

97104
------------------------------------------------------------------------------------
@@ -108,6 +115,7 @@ create or replace function _partition_over(
108115
returns TABLE(of_date date)
109116
language plpgsql
110117
as $$
118+
-- play-ebean-start
111119
declare
112120
endDate date;
113121
begin
@@ -132,6 +140,7 @@ begin
132140
return query select s::date from generate_series(fromDate, endDate, '1 month') s;
133141
end if;
134142
end;
143+
-- play-ebean-end
135144
$$;
136145

137146

@@ -158,11 +167,13 @@ create or replace function partition(
158167
language plpgsql
159168
set timezone to 'UTC'
160169
as $$
170+
-- play-ebean-start
161171
begin
162172
perform _partition_create(_partition_meta(mode, poDate, baseName, schemaName))
163173
from _partition_over(mode, fromDate, partitionCount) poDate;
164174
return 'done';
165175
end;
176+
-- play-ebean-end
166177
$$;
167178
</ddl-script>
168179

ebean-ddl-generator/src/main/resources/io/ebeaninternal/dbmigration/builtin-extra-ddl.xml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ GO
2424
-- deletes all indices referring to TABLE.COLUMN
2525
--
2626
CREATE OR ALTER PROCEDURE usp_ebean_drop_indices @tableName nvarchar(255), @columnName nvarchar(255)
27-
AS SET NOCOUNT ON
27+
AS
28+
-- play-ebean-start
29+
SET NOCOUNT ON
2830
declare @sql nvarchar(1000)
2931
declare @indexName nvarchar(255)
3032
BEGIN
@@ -44,14 +46,17 @@ BEGIN
4446
CLOSE index_cursor;
4547
DEALLOCATE index_cursor;
4648
END
49+
-- play-ebean-end
4750
GO
4851

4952
--
5053
-- PROCEDURE: usp_ebean_drop_default_constraint TABLE, COLUMN
5154
-- deletes the default constraint, which has a random name
5255
--
5356
CREATE OR ALTER PROCEDURE usp_ebean_drop_default_constraint @tableName nvarchar(255), @columnName nvarchar(255)
54-
AS SET NOCOUNT ON
57+
AS
58+
-- play-ebean-start
59+
SET NOCOUNT ON
5560
declare @tmp nvarchar(1000)
5661
BEGIN
5762
select @tmp = t1.name from sys.default_constraints t1
@@ -60,14 +65,17 @@ BEGIN
6065

6166
if @tmp is not null EXEC('alter table [' + @tableName +'] drop constraint ' + @tmp);
6267
END
68+
-- play-ebean-end
6369
GO
6470

6571
--
6672
-- PROCEDURE: usp_ebean_drop_constraints TABLE, COLUMN
6773
-- deletes constraints and foreign keys refering to TABLE.COLUMN
6874
--
6975
CREATE OR ALTER PROCEDURE usp_ebean_drop_constraints @tableName nvarchar(255), @columnName nvarchar(255)
70-
AS SET NOCOUNT ON
76+
AS
77+
-- play-ebean-start
78+
SET NOCOUNT ON
7179
declare @sql nvarchar(1000)
7280
declare @constraintName nvarchar(255)
7381
BEGIN
@@ -93,14 +101,17 @@ BEGIN
93101
CLOSE name_cursor;
94102
DEALLOCATE name_cursor;
95103
END
104+
-- play-ebean-end
96105
GO
97106

98107
--
99108
-- PROCEDURE: usp_ebean_drop_column TABLE, COLUMN
100109
-- deletes the column annd ensures that all indices and constraints are dropped first
101110
--
102111
CREATE OR ALTER PROCEDURE usp_ebean_drop_column @tableName nvarchar(255), @columnName nvarchar(255)
103-
AS SET NOCOUNT ON
112+
AS
113+
-- play-ebean-start
114+
SET NOCOUNT ON
104115
declare @sql nvarchar(1000)
105116
BEGIN
106117
EXEC usp_ebean_drop_indices @tableName, @columnName;
@@ -110,6 +121,7 @@ BEGIN
110121
set @sql = 'alter table [' + @tableName + '] drop column [' + @columnName + ']';
111122
EXECUTE(@sql);
112123
END
124+
-- play-ebean-end
113125
GO
114126
</ddl-script>
115127
<ddl-script name="create procs" platforms="mysql mariadb" init="true">-- Inital script to create stored procedures etc for mysql platform
@@ -121,6 +133,7 @@ delimiter $$
121133
-- deletes all constraints and foreign keys referring to TABLE.COLUMN
122134
--
123135
CREATE PROCEDURE usp_ebean_drop_foreign_keys(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
136+
-- play-ebean-start
124137
BEGIN
125138
DECLARE done INT DEFAULT FALSE;
126139
DECLARE c_fk_name CHAR(255);
@@ -143,6 +156,7 @@ END LOOP;
143156

144157
CLOSE curs;
145158
END
159+
-- play-ebean-end
146160
$$
147161

148162
DROP PROCEDURE IF EXISTS usp_ebean_drop_column;
@@ -153,12 +167,14 @@ delimiter $$
153167
-- deletes the column and ensures that all indices and constraints are dropped first
154168
--
155169
CREATE PROCEDURE usp_ebean_drop_column(IN p_table_name VARCHAR(255), IN p_column_name VARCHAR(255))
170+
-- play-ebean-start
156171
BEGIN
157172
CALL usp_ebean_drop_foreign_keys(p_table_name, p_column_name);
158173
SET @sql = CONCAT('ALTER TABLE `', p_table_name, '` DROP COLUMN `', p_column_name, '`');
159174
PREPARE stmt FROM @sql;
160175
EXECUTE stmt;
161176
END
177+
-- play-ebean-end
162178
$$
163179
</ddl-script>
164180

@@ -170,6 +186,7 @@ delimiter $$
170186
--
171187
CREATE OR REPLACE PROCEDURE usp_ebean_drop_foreign_keys(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256))
172188
AS
189+
-- play-ebean-start
173190
BEGIN
174191
DECLARE foreign_key_names TABLE(CONSTRAINT_NAME NVARCHAR(256), TABLE_NAME NVARCHAR(256));
175192
DECLARE i INT;
@@ -181,6 +198,7 @@ EXEC 'ALTER TABLE "' || ESCAPE_DOUBLE_QUOTES(:foreign_key_names.TABLE_NAME[i]) |
181198
END FOR;
182199

183200
END;
201+
-- play-ebean-end
184202
$$
185203

186204
delimiter $$
@@ -190,10 +208,12 @@ delimiter $$
190208
--
191209
CREATE OR REPLACE PROCEDURE usp_ebean_drop_column(IN table_name NVARCHAR(256), IN column_name NVARCHAR(256))
192210
AS
211+
-- play-ebean-start
193212
BEGIN
194213
CALL usp_ebean_drop_foreign_keys(table_name, column_name);
195214
EXEC 'ALTER TABLE "' || UPPER(ESCAPE_DOUBLE_QUOTES(table_name)) || '" DROP ("' || UPPER(ESCAPE_DOUBLE_QUOTES(column_name)) || '")';
196215
END;
216+
-- play-ebean-end
197217
$$
198218
</ddl-script>
199219
</extra-ddl>

0 commit comments

Comments
 (0)