forked from kurkop/flyway-postgres-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-migration.sh
31 lines (22 loc) · 856 Bytes
/
pre-migration.sh
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
#! /bin/bash
## delete old files
cd /flyway/conf/
export PGUSER=$(grep -i flyway.user flyway.conf | awk -F "=" '{print $2}')
export PGPASSWORD=$(grep -i flyway.password flyway.conf | awk -F "=" '{print $2}')
export PGHOST=$(grep -i flyway.url flyway.conf | awk -F "/" '{print $3}' | awk -F ":" '{print $1}')
export PGDATABASE=$(grep -i flyway.url flyway.conf | awk -F "/" '{print $4}')
cd /flyway/sql/
for f in *
do
_date=$(date +"V%Y%m%d%H%M%S%N__")
mv "$f" "$_date$f"
done
psql -t -c"SELECT script FROM flyway_schema_records WHERE script !='<< Flyway Baseline >>';" >to_delete_files.sh
while read file
do
echo $file | awk -F"__V" '{print "rm -rf *"$2}' | grep -i sql >>Delete_Files.sh
done < to_delete_files.sh
bash Delete_Files.sh
## delete old files
cd /flyway/conf/
psql -c"DELETE FROM flyway_schema_history WHERE installed_rank >1;"