#** Special macro to add table column with default null **# #macro(addColumnNull $table $column $type) #if ($db.DBTYPE == "ORACLE") alter table $table add $column $type default null; #else alter table $table add column $column $type default null; #end #end #** Special macro to add table column with not-null restriction and default value **# #macro(addColumnNotNull $table $column $type $default) #if($db.DBTYPE == "MYSQL" || $db.DBTYPE=="HSQDB") alter table $table add column $column $type default $default not null; #elseif ($db.DBTYPE == "POSTGRESQL") alter table $table add column $column $type; alter table $table alter $column set default $default; update $table set $column=$default; alter table $table alter $column set not null; #elseif ($db.DBTYPE == "HSQLDB") alter table $table add column $column $type default $default not null; #elseif ($db.DBTYPE == "DERBY" || $db.DBTYPE == "DB2") alter table $table add column $column $type with default $default not null; #elseif ($db.DBTYPE == "ORACLE") alter table $table add $column $type default $default not null; #end #end #** Special macro to drop NOT NULL requirement from an 'id' column. **# #macro(dropNotNullFromTableId $table) #if($db.DBTYPE == "MYSQL") alter table $table drop primary key; alter table $table modify id varchar(48) null; #elseif ($db.DBTYPE == "POSTGRESQL") alter table $table drop constraint "${table}_pkey"; alter table $table alter column id drop not null; #elseif ($db.DBTYPE == "HSQLDB") alter table $table alter column id varchar(48) null; #elseif ($db.DBTYPE == "DERBY" || $db.DBTYPE == "DB2") alter table $table drop primary key; alter table $table alter column id null; #elseif ($db.DBTYPE == "ORACLE") alter table $table drop primary key; #end #end #** Define non-null column with default value **# #macro(columnNotNullWithDefault $columnName $columnType $defaultValue) #if($db.DBTYPE == "ORACLE") $columnName $columnType default '$defaultValue' not null #else $columnName $columnType not null default '$defaultValue' #end #end #** Macro to account for lack of comparable long varchar in MySQL **# #macro(longtext $size) #if($db.DBTYPE == "MYSQL") text #else varchar($size) #end #end #macro(dropIndex $indexName $tableName) #if ($db.DBTYPE == "DERBY" || $db.DBTYPE == 'POSTGRESQL') drop index $indexName #else drop index $indexName on $tableName; #end #end #macro(dropColumn $tableName $columnName) #if ($db.DBTYPE == "DERBY") -- You should alter table $tableName drop column $columnName; #else alter table $tableName drop column $columnName; #end #end #macro(dropTableIfExists $tableName) #if ($db.DBTYPE == "DERBY") -- You should drop table $tableName if it exists #else drop table if exists $tableName; #end #end