Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scheduler/app/database/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
DB_HOST = os.getenv("DB_HOST", "seatable-mysql")
DB_PORT = int(os.getenv("DB_PORT", "3306"))
DATABASE_NAME = os.getenv("DATABASE_NAME", "scheduler")
# All upgrade statements start from 2.2.4, but here it is not actually 2.2.4—it's just a default value.
CURRENT_VERSION = os.getenv("VERSION", "2.2.4")


def wait_for_mysql():
Expand Down Expand Up @@ -57,4 +59,18 @@ def wait_for_mysql():
)
os.system(sql)

# Write the current version number directly during the initial deployment.
sql = (
'mysql -h %s -u%s -p%s %s -e "INSERT INTO version_history (version, update_at) '
"SELECT '%s', NOW() WHERE NOT EXISTS (SELECT 1 FROM version_history LIMIT 1);\""
% (
shlex.quote(DB_HOST),
shlex.quote(db_user),
shlex.quote(db_passwd),
DATABASE_NAME,
CURRENT_VERSION,
)
)
os.system(sql)

print("Initalization of database successful")
8 changes: 4 additions & 4 deletions scheduler/app/upgrade/6.2.0.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

ALTER TABLE script_log MODIFY started_at DATETIME(6);

ALTER TABLE script_log ADD COLUMN state VARCHAR(10);
ALTER TABLE script_log ADD KEY state_h3u8i9o1_key (state);
ALTER TABLE script_log ADD COLUMN IF NOT EXISTS state VARCHAR(10);
ALTER TABLE script_log ADD INDEX IF NOT EXISTS state_h3u8i9o1_key (state);

ALTER TABLE script_log ADD COLUMN created_at DATETIME(6);
ALTER TABLE script_log ADD KEY created_at_h3u7y9o4_key (created_at);
ALTER TABLE script_log ADD COLUMN IF NOT EXISTS created_at DATETIME(6);
ALTER TABLE script_log ADD INDEX IF NOT EXISTS created_at_h3u7y9o4_key (created_at);
UPDATE script_log SET created_at=started_at;
Loading