From 1fbb051d2ecd4956fcd0bbe41aa79239c8dacdf3 Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Fri, 10 Jan 2025 10:47:55 -0500 Subject: [PATCH] use show tables to list all tables in db to drop when importing db --- bin/import_db.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/import_db.sh b/bin/import_db.sh index 4e93ce3..6ef9f26 100755 --- a/bin/import_db.sh +++ b/bin/import_db.sh @@ -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