Skip to content

Commit

Permalink
こんな感じでDB再起動の時に一度migrationをかける
Browse files Browse the repository at this point in the history
  • Loading branch information
yamachu committed Jul 23, 2022
1 parent a0e748c commit 97a5f7b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ log_rotate/mysql:
cd /home/isucon; mysqladmin flush-logs

restart/mysql:
sudo systemctl restart mysql
sudo systemctl restart mysql
/home/isucon/webapp/sql/format.sh
2 changes: 2 additions & 0 deletions sql/admin/20_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create index player_id_idx on visit_history(player_id);
create index tenant_id_competition_id_idx on visit_history(tenant_id,competition_id);
23 changes: 23 additions & 0 deletions sql/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

set -ex
cd `dirname $0`

ISUCON_DB_HOST=${ISUCON_DB_HOST:-127.0.0.1}
ISUCON_DB_PORT=${ISUCON_DB_PORT:-3306}
ISUCON_DB_USER=${ISUCON_DB_USER:-isucon}
ISUCON_DB_PASSWORD=${ISUCON_DB_PASSWORD:-isucon}
ISUCON_DB_NAME=${ISUCON_DB_NAME:-isuports}

# MySQLを初期化
for f in admin/10_schema.sql admin/90_data.sql init.sql admin/20_migration;do
mysql -u"$ISUCON_DB_USER" \
-p"$ISUCON_DB_PASSWORD" \
--host "$ISUCON_DB_HOST" \
--port "$ISUCON_DB_PORT" \
"$ISUCON_DB_NAME" < $f
done

# SQLiteのデータベースを初期化
rm -f ../tenant_db/*.db
cp -r ../../initial_data/*.db ../tenant_db/

0 comments on commit 97a5f7b

Please sign in to comment.