Skip to content

Commit

Permalink
update import script
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jan 11, 2025
1 parent 1fbb051 commit de99b24
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions bin/import_db.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/bin/bash
dump=$1

echo 'show tables;' | rails db -p | grep -v "Tables_in_" | xargs -i -n 1 echo "DROP TABLE IF EXISTS \`{}\`;" > drop.sql
echo 'SET foreign_key_checks = 0;' > 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
[ -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

rake admin:reindex_all

0 comments on commit de99b24

Please sign in to comment.