-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalter.sql
64 lines (61 loc) · 2.85 KB
/
alter.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
----- ${application.name}_alter.sql -----
drop procedure if exists addNewColumns;
delimiter //
create procedure addNewColumns()
begin
declare continue handler for 1060 begin end;
#foreach( $entity in $application.entities )
#if (!$singleEntity || $singleEntity == ${tr.f_v($entity.name)})
#set ($prevCol = "${tr.f_v($entity.prefix)}_id")
#foreach( $property in $entity.properties )
#set ($definition = "NOT_IMPLEMENTED-IN-ALTER")
#if (${tr.f_v($property.dataType.name)} == "varchar")
#set ($definition = "VARCHAR($property.size)")
#elseif (${tr.f_v($property.dataType.name)} == "integer")
#set ($definition = "INT(11)")
#elseif (${tr.f_v($property.dataType.name)} == "decimal")
#set ($definition = "decimal(10,2)")
#elseif (${tr.f_v($property.dataType.name)} == "bool")
#set ($definition = "boolean")
#elseif (${tr.f_v($property.dataType.name)} == "text")
#set ($definition = "mediumtext")
#elseif (${tr.f_v($property.dataType.name)} == "date")
#set ($definition = "DATE")
#elseif (${tr.f_v($property.dataType.name)} == "datetime")
#set ($definition = "DATETIME")
#elseif (${tr.f_v($property.dataType.name)} == "email")
#set ($definition = "VARCHAR(255)")
#elseif (${tr.f_v($property.dataType.name)} == "code")
#set ($definition = "LONGTEXT")
#elseif (${tr.f_v($property.dataType.name)} == "password")
#set ($definition = "VARCHAR(2000)")
#elseif (${tr.f_v($property.dataType.name)} == "url")
#set ($definition = "VARCHAR(255)")
#elseif (${tr.f_v($property.dataType.name)} == "color")
#set ($definition = "VARCHAR(20)")
#end
#if ($definition == "NOT_IMPLEMENTED-IN-ALTER") -- #end ALTER TABLE `${tr.f_v($application.prefix)}_${tr.f_v($entity.namePlural)}` ADD COLUMN `${entity.prefix}_${tr.f_v($property.name)}` $definition AFTER $prevCol ;
#if ($definition != "NOT_IMPLEMENTED-IN-ALTER")
#set ($prevCol = "${tr.f_v($entity.prefix)}_${tr.f_v($property.name)}")
#end
#end
#foreach( $relation in $entity.childRelations )
#if ($relation.name && $relation.name != "null")
ALTER TABLE `${tr.f_v($application.prefix)}_${tr.f_v($entity.namePlural)}` ADD COLUMN `${tr.f_v($entity.prefix)}_${tr.f_v($relation.parentEntity.prefix)}_${tr.f_v($relation.name)}_id` int(11) default NULL AFTER $prevCol ;
#set ($prevCol = "${tr.f_v($entity.prefix)}_${tr.f_v($relation.parentEntity.prefix)}_${tr.f_v($relation.name)}_id")
#else
ALTER TABLE `${tr.f_v($application.prefix)}_${tr.f_v($entity.namePlural)}` ADD COLUMN `${tr.f_v($entity.prefix)}_${tr.f_v($relation.parentEntity.prefix)}_id` int(11) default NULL AFTER $prevCol ;
#set ($prevCol = "${tr.f_v($entity.prefix)}_${tr.f_v($relation.parentEntity.prefix)}_id")
#end
#end
#end
#end
end//
delimiter ;
call addNewColumns();
#foreach( $entity in $application.entities )
UPDATE prt_portlet_definitions
SET pdf_version = '${application.versionMain}.${application.version}'
WHERE pdf_namespace = '${tr.f_v($application.name)}'
AND pdf_alias = 'virgo${tr.FV($entity.name)}';
#end