Skip to content
Open
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
64 changes: 64 additions & 0 deletions database/migrations/000114_drop_legacy_entity_tables.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-- SPDX-FileCopyrightText: Copyright 2025 The Minder Authors
-- SPDX-License-Identifier: Apache-2.0

BEGIN;

-- WARNING: This down migration recreates the table structure ONLY.
-- It does NOT restore any data that was deleted when the tables were dropped.
-- This is for structural rollback only - data recovery requires restoring from backup.

-- Recreate repositories table
CREATE TABLE repositories (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
provider TEXT NOT NULL,
project_id UUID NOT NULL,
repo_owner TEXT NOT NULL,
repo_name TEXT NOT NULL,
repo_id INTEGER NOT NULL,
is_private BOOLEAN NOT NULL,
is_fork BOOLEAN NOT NULL,
webhook_id INTEGER,
webhook_url TEXT NOT NULL,
deploy_url TEXT NOT NULL,
clone_url TEXT NOT NULL,
default_branch TEXT,
license VARCHAR(255) DEFAULT 'unknown',
provider_id UUID,
reminder_last_sent TIMESTAMP,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
FOREIGN KEY (project_id, provider) REFERENCES providers(project_id, name) ON DELETE CASCADE
);

ALTER TABLE repositories ADD CONSTRAINT unique_repo_id UNIQUE (repo_id);
ALTER TABLE repositories ADD CONSTRAINT fk_repositories_provider_id FOREIGN KEY (provider_id) REFERENCES providers (id) ON DELETE CASCADE;

-- Recreate artifacts table
CREATE TABLE artifacts (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
repository_id UUID NOT NULL REFERENCES repositories(id) ON DELETE CASCADE,
artifact_name TEXT NOT NULL,
artifact_type TEXT NOT NULL,
artifact_visibility TEXT NOT NULL,
project_id UUID,
provider_id UUID,
provider_name TEXT,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

ALTER TABLE artifacts ADD CONSTRAINT fk_artifacts_project_id FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE;
ALTER TABLE artifacts ADD CONSTRAINT fk_artifacts_provider_id_and_name FOREIGN KEY (provider_id, provider_name) REFERENCES providers (id, name) ON DELETE CASCADE;

-- Recreate pull_requests table
CREATE TABLE pull_requests (
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
repository_id UUID NOT NULL REFERENCES repositories(id) ON DELETE CASCADE,
pr_number BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE UNIQUE INDEX pr_in_repo_unique ON pull_requests (repository_id, pr_number);

COMMIT;
16 changes: 16 additions & 0 deletions database/migrations/000114_drop_legacy_entity_tables.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- SPDX-FileCopyrightText: Copyright 2025 The Minder Authors
-- SPDX-License-Identifier: Apache-2.0

BEGIN;

-- Drop legacy entity tables in correct order (respecting foreign keys)
-- These tables have been fully replaced by the unified entity_instances and properties tables.
-- All code has been migrated to use the new entity model.

-- WARNING: This is a destructive operation. Ensure backups exist before running.

DROP TABLE IF EXISTS pull_requests CASCADE;
DROP TABLE IF EXISTS artifacts CASCADE;
DROP TABLE IF EXISTS repositories CASCADE;

COMMIT;
12 changes: 4 additions & 8 deletions database/mock/fixtures/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ func WithSuccessfulGetFeatureInProject(
}

func WithSuccessfulUpsertPullRequest(
pullRequest db.PullRequest,
instance db.EntityInstance,
) func(*mockdb.MockStore) {
return func(mockStore *mockdb.MockStore) {
mockStore.EXPECT().
CreateOrEnsureEntityByID(gomock.Any(), gomock.Any()).
Return(db.EntityInstance{}, nil)
Return(instance, nil)
}
}

Expand Down Expand Up @@ -131,7 +131,6 @@ func (m createOrEnsureEntityByIDParamsMatcher) Matches(x interface{}) bool {
}

func WithSuccessfulUpsertPullRequestWithParams(
pullRequest db.PullRequest,
instance db.EntityInstance,
entParams db.CreateOrEnsureEntityByIDParams,
) func(*mockdb.MockStore) {
Expand All @@ -144,15 +143,12 @@ func WithSuccessfulUpsertPullRequestWithParams(
}

func WithSuccessfulUpsertArtifact(
artifact db.Artifact,
instance db.EntityInstance,
) func(*mockdb.MockStore) {
return func(mockStore *mockdb.MockStore) {
mockStore.EXPECT().
UpsertArtifact(gomock.Any(), gomock.Any()).
Return(artifact, nil)
mockStore.EXPECT().
CreateOrEnsureEntityByID(gomock.Any(), gomock.Any()).
Return(db.EntityInstance{}, nil)
Return(instance, nil)
}
}

Expand Down
72 changes: 0 additions & 72 deletions database/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions database/query/artifacts.sql

This file was deleted.

26 changes: 0 additions & 26 deletions database/query/repositories.sql

This file was deleted.

76 changes: 0 additions & 76 deletions internal/db/artifacts.sql.go

This file was deleted.

Loading