Skip to content

Commit

Permalink
feat: migrate existing mods to use targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Aug 20, 2023
1 parent 7d39754 commit 6d7c4f3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions migrations/sql/000022_update_mod_targets.down.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- ID generation --
-- This is not as random as the original ID, but it should be good enough --
Create or replace function update_mod_platform_down_random_string(length integer) returns text as
$$
declare
Expand All @@ -15,6 +17,7 @@ begin
end;
$$ language plpgsql;

-- Mod version targets --
ALTER TABLE version_targets RENAME TO mod_archs;

ALTER TABLE mod_archs
Expand All @@ -24,7 +27,6 @@ ALTER TABLE mod_archs
ALTER TABLE mod_archs
ADD COLUMN id varchar(14);

-- This is not as random as the original ID, but it should be good enough
UPDATE mod_archs SET id = update_mod_platform_down_random_string(14) WHERE true;

ALTER TABLE mod_archs
Expand All @@ -37,6 +39,7 @@ ALTER TABLE mod_archs

CREATE INDEX IF NOT EXISTS idx_mod_arch_id ON mod_archs (mod_version_arch_id, platform);

-- SML version targets --
ALTER TABLE sml_version_targets RENAME TO sml_archs;

ALTER TABLE sml_archs
Expand All @@ -46,7 +49,6 @@ ALTER TABLE sml_archs
ALTER TABLE sml_archs
ADD COLUMN id varchar(14);

-- This is not as random as the original ID, but it should be good enough
UPDATE sml_archs SET id = update_mod_platform_down_random_string(14) WHERE true;

ALTER TABLE sml_archs
Expand Down
2 changes: 2 additions & 0 deletions migrations/sql/000022_update_mod_targets.up.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Mod version targets --
ALTER TABLE mod_archs RENAME TO version_targets;

DROP INDEX idx_mod_arch_id;
Expand All @@ -15,6 +16,7 @@ ALTER TABLE version_targets

ALTER TABLE sml_archs RENAME TO sml_version_targets;

-- SML version targets --
DROP INDEX idx_sml_archs_id;

ALTER TABLE sml_version_targets
Expand Down
15 changes: 15 additions & 0 deletions migrations/sql/000023_migrate_versions_to_targets.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--Mod Targets--
DELETE FROM version_targets
USING versions
WHERE version_targets.version_id = versions.id AND
version_targets.target_name = 'Windows' AND
version_targets.key = versions.key AND
version_targets.hash = versions.hash AND
version_targets.size = versions.size;

--SML Targets--
DELETE FROM sml_version_targets
USING sml_versions
WHERE sml_version_targets.version_id = sml_versions.id AND
sml_version_targets.target_name = 'Windows' AND
sml_version_targets.link = replace(sml_versions.link, '/tag/', '/download/') || '/SML.zip';
10 changes: 10 additions & 0 deletions migrations/sql/000023_migrate_versions_to_targets.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Mod Targets --
INSERT INTO version_targets (version_id, target_name, key, hash, size)
SELECT id, 'Windows', key, hash, size
FROM versions;

-- SML Targets --
INSERT INTO sml_version_targets (version_id, target_name, link)
SELECT id, 'Windows', replace(link, '/tag/', '/download/') || '/SML.zip'
FROM sml_versions
WHERE version LIKE '3%';

0 comments on commit 6d7c4f3

Please sign in to comment.