Skip to content

Commit

Permalink
use show tables to list all tables in db to drop when importing db
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jan 10, 2025
1 parent 2faffcc commit 1fbb051
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bin/import_db.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash
dump=$1

[ -f "$dump" ] && zcat -f "$dump" | grep 'DROP TABLE ' > drop.sql
echo 'show tables;' | rails db -p | grep -v "Tables_in_" | xargs -i -n 1 echo "DROP TABLE IF EXISTS \`{}\`;" > 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
Expand Down

0 comments on commit 1fbb051

Please sign in to comment.