Skip to content

Commit

Permalink
drop tables instead of database in import script
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jan 9, 2025
1 parent 244a5bb commit 1991cd9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/import_db.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash
dump=$1

[ -f "$dump" ] && rails db:drop && rails db:create && zcat -f "$dump" | sed '/DROP DATABASE \|CREATE DATABASE \|USE `/d' | sed 's/ datetime / datetime(6) /' > import.sql
[ -f "$dump" ] && zcat -f "$dump" | grep 'DROP TABLE ' > drop.sql
[ -f "$dump" ] && zcat -f "$dump" | sed '/DROP DATABASE \|CREATE DATABASE \|USE `/d' | sed 's/ datetime / datetime(6) /' > import.sql

cat drop.sql | rails db -p
cat import.sql | rails db -p

rails db:migrate
Expand Down

0 comments on commit 1991cd9

Please sign in to comment.