@@ -618,6 +618,88 @@ pub fn migrate(version: Option<Version>, conn: &mut Client) -> CratesfyiResult<(
618
618
DROP INDEX github_repos_stars_idx;
619
619
" ,
620
620
) ,
621
+ migration!(
622
+ context,
623
+ 27 ,
624
+ // description
625
+ "Add gitlab handling: creation of the new repositories table which replaces and extend \
626
+ github_repos",
627
+ // upgrade query
628
+ "
629
+ CREATE TABLE repositories (
630
+ id SERIAL PRIMARY KEY,
631
+ host VARCHAR NOT NULL,
632
+ host_id VARCHAR NOT NULL,
633
+ name VARCHAR NOT NULL,
634
+ description VARCHAR,
635
+ last_commit TIMESTAMPTZ,
636
+ stars INT NOT NULL,
637
+ forks INT NOT NULL,
638
+ issues INT NOT NULL,
639
+ updated_at TIMESTAMPTZ NOT NULL,
640
+ UNIQUE (host, host_id)
641
+ );
642
+
643
+ ALTER TABLE releases ADD COLUMN repository INTEGER
644
+ REFERENCES repositories(id) ON DELETE SET NULL;
645
+
646
+ INSERT INTO repositories(host, host_id, name, description, last_commit, stars, forks, issues, updated_at)
647
+ SELECT 'github', id, name, description, last_commit, stars, forks, issues, updated_at
648
+ FROM github_repos;
649
+
650
+ UPDATE releases
651
+ SET repository = repositories.id
652
+ FROM repositories
653
+ WHERE releases.github_repo IS NOT NULL AND repositories.host_id = releases.github_repo;
654
+
655
+ DROP INDEX releases_github_repo_idx;
656
+ DROP INDEX github_repos_stars_idx;
657
+
658
+ CREATE INDEX releases_github_repo_idx ON releases(repository);
659
+ CREATE INDEX github_repos_stars_idx ON repositories(stars DESC);
660
+
661
+ ALTER TABLE releases
662
+ DROP COLUMN github_repo;
663
+
664
+ DROP TABLE github_repos;
665
+ " ,
666
+ // downgrade query
667
+ "
668
+ CREATE TABLE github_repos (
669
+ id VARCHAR PRIMARY KEY NOT NULL,
670
+ name VARCHAR NOT NULL,
671
+ description VARCHAR,
672
+ last_commit TIMESTAMPTZ,
673
+ stars INT NOT NULL,
674
+ forks INT NOT NULL,
675
+ issues INT NOT NULL,
676
+ updated_at TIMESTAMPTZ NOT NULL
677
+ );
678
+
679
+ ALTER TABLE releases ADD COLUMN github_repo VARCHAR
680
+ REFERENCES github_repos(id) ON DELETE SET NULL;
681
+
682
+ INSERT INTO github_repos(id, name, description, last_commit, stars, forks, issues, updated_at)
683
+ SELECT host_id, name, description, last_commit, stars, forks, issues, updated_at
684
+ FROM repositories WHERE repositories.host = 'github';
685
+
686
+ UPDATE releases
687
+ SET github_repo = repositories.host_id
688
+ FROM repositories
689
+ WHERE repositories.host_id = releases.github_repo AND releases.repository IS NOT NULL AND repositories.host = 'github';
690
+
691
+ DROP INDEX releases_github_repo_idx;
692
+ DROP INDEX github_repos_stars_idx;
693
+
694
+ CREATE INDEX releases_github_repo_idx ON releases (github_repo);
695
+ CREATE INDEX github_repos_stars_idx ON github_repos(stars DESC);
696
+
697
+ ALTER TABLE releases
698
+ DROP COLUMN repository;
699
+
700
+ DROP TABLE repository;
701
+ "
702
+ ) ,
621
703
] ;
622
704
623
705
for migration in migrations {
0 commit comments