forked from buerokratt/Common-Knowledge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-migration.sh
More file actions
executable file
·42 lines (31 loc) · 2.12 KB
/
create-migration.sh
File metadata and controls
executable file
·42 lines (31 loc) · 2.12 KB
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
#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo 'specify descriptive name for migration file'
exit 0
fi
timestamp=$(date '+%Y%m%d%H%M%S')
base_path="DSL/Liquibase/"
sql_migration_file="changelog/${timestamp}-$1.sql"
sql_migration_file_path="${base_path}${sql_migration_file}"
echo "-- liquibase formatted sql" > "$sql_migration_file_path"
echo "-- changeset $(git config user.name):$timestamp ignore:true" >> "$sql_migration_file_path"
echo "SQL Migration file created: $sql_migration_file_path"
rollback_sql_migration_file="changelog/${timestamp}-rollback.sql"
rollback_sql_migration_file_path="${base_path}${rollback_sql_migration_file}"
echo "-- liquibase formatted sql" > "$rollback_sql_migration_file_path"
echo "-- changeset $(git config user.name):$timestamp ignore:true" >> "$rollback_sql_migration_file_path"
echo "Rollback Migration file created: $rollback_sql_migration_file_path"
liquibase_migration_file_path="DSL/Liquibase/changelog/${timestamp}-$1.xml"
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "$liquibase_migration_file_path"
echo "<databaseChangeLog xmlns=\"http://www.liquibase.org/xml/ns/dbchangelog\"" >> "$liquibase_migration_file_path"
echo " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" >> "$liquibase_migration_file_path"
echo " xsi:schemaLocation=\"http://www.liquibase.org/xml/ns/dbchangelog" >> "$liquibase_migration_file_path"
echo "http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd\">" >> "$liquibase_migration_file_path"
echo " <changeSet id=\"$timestamp\" author=\"$(git config user.name)\">" >> "$liquibase_migration_file_path"
echo " <sqlFile path=\"${sql_migration_file}\" />" >> "$liquibase_migration_file_path"
echo " <rollback>" >> "$liquibase_migration_file_path"
echo " <sqlFile path=\"${rollback_sql_migration_file}\" />" >> "$liquibase_migration_file_path"
echo " </rollback>" >> "$liquibase_migration_file_path"
echo " </changeSet>" >> "$liquibase_migration_file_path"
echo "</databaseChangeLog>" >> "$liquibase_migration_file_path"
echo "Liquibase migration file created: $liquibase_migration_file_path"