From 4a582e8079178a7ac11f2a492e7988fcdaa210cd Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 23 Jul 2022 23:40:25 +0200 Subject: store active version id in bots table --- .../migrations/2022-07-23-131936_bot_active_version/down.sql | 2 ++ .../migrations/2022-07-23-131936_bot_active_version/up.sql | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 planetwars-server/migrations/2022-07-23-131936_bot_active_version/down.sql create mode 100644 planetwars-server/migrations/2022-07-23-131936_bot_active_version/up.sql (limited to 'planetwars-server/migrations/2022-07-23-131936_bot_active_version') diff --git a/planetwars-server/migrations/2022-07-23-131936_bot_active_version/down.sql b/planetwars-server/migrations/2022-07-23-131936_bot_active_version/down.sql new file mode 100644 index 0000000..444fe51 --- /dev/null +++ b/planetwars-server/migrations/2022-07-23-131936_bot_active_version/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE bots DROP COLUMN active_version; \ No newline at end of file diff --git a/planetwars-server/migrations/2022-07-23-131936_bot_active_version/up.sql b/planetwars-server/migrations/2022-07-23-131936_bot_active_version/up.sql new file mode 100644 index 0000000..8ea398b --- /dev/null +++ b/planetwars-server/migrations/2022-07-23-131936_bot_active_version/up.sql @@ -0,0 +1,12 @@ +-- Your SQL goes here +ALTER TABLE bots ADD COLUMN active_version INTEGER REFERENCES bot_versions(id); + +-- set most recent bot verison as active +UPDATE bots +SET active_version = most_recent.id +FROM ( + SELECT DISTINCT ON (bot_id) id, bot_id + FROM bot_versions + ORDER BY bot_id, created_at DESC + ) most_recent +WHERE bots.id = most_recent.bot_id; \ No newline at end of file -- cgit v1.2.3