Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove temporary migrations and unused queries #4277

Merged
merged 1 commit into from
Aug 26, 2024
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
20 changes: 0 additions & 20 deletions cmd/server/app/migrate_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/stacklok/minder/internal/authz"
"github.com/stacklok/minder/internal/config"
serverconfig "github.com/stacklok/minder/internal/config/server"
"github.com/stacklok/minder/internal/db"
"github.com/stacklok/minder/internal/logger"
)

Expand Down Expand Up @@ -112,25 +111,6 @@ var upCmd = &cobra.Command{
return fmt.Errorf("error preparing authz client: %w", err)
}

cmd.Println("Performing entity migrations...")
store := db.NewStore(dbConn)

if err := store.TemporaryPopulateRepositories(ctx); err != nil {
cmd.Printf("Error while populating entities table with repos: %v\n", err)
}

if err := store.TemporaryPopulateArtifacts(ctx); err != nil {
cmd.Printf("Error while populating entities table with artifacts: %v\n", err)
}

if err := store.TemporaryPopulatePullRequests(ctx); err != nil {
cmd.Printf("Error while populating entities table with pull requests: %v\n", err)
}

if err := store.TemporaryPopulateEvaluationHistory(ctx); err != nil {
cmd.Printf("Error while populating entities table with evaluation history: %v\n", err)
}

return nil
},
}
Expand Down
86 changes: 0 additions & 86 deletions database/mock/store.go

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

17 changes: 0 additions & 17 deletions database/query/entities.sql
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,6 @@ LIMIT 1;
SELECT * FROM entity_instances
WHERE entity_instances.entity_type = $1 AND entity_instances.project_id = ANY(sqlc.arg(projects)::uuid[]);

-- name: TemporaryPopulateRepositories :exec
INSERT INTO entity_instances (id, entity_type, name, project_id, provider_id, created_at)
SELECT id, 'repository', repo_owner || '/' || repo_name, project_id, provider_id, created_at FROM repositories
WHERE NOT EXISTS (SELECT 1 FROM entity_instances WHERE entity_instances.id = repositories.id AND entity_instances.entity_type = 'repository');

-- name: TemporaryPopulateArtifacts :exec
INSERT INTO entity_instances (id, entity_type, name, project_id, provider_id, created_at, originated_from)
SELECT artifacts.id, 'artifact', LOWER(repositories.repo_owner) || '/' || artifacts.artifact_name, repositories.project_id, repositories.provider_id, artifacts.created_at, artifacts.repository_id FROM artifacts
JOIN repositories ON repositories.id = artifacts.repository_id
WHERE NOT EXISTS (SELECT 1 FROM entity_instances WHERE entity_instances.id = artifacts.id AND entity_instances.entity_type = 'artifact');

-- name: TemporaryPopulatePullRequests :exec
INSERT INTO entity_instances (id, entity_type, name, project_id, provider_id, created_at, originated_from)
SELECT pull_requests.id, 'pull_request', repositories.repo_owner || '/' || repositories.repo_name || '/' || pull_requests.pr_number::TEXT, repositories.project_id, repositories.provider_id, pull_requests.created_at, pull_requests.repository_id FROM pull_requests
JOIN repositories ON repositories.id = pull_requests.repository_id
WHERE NOT EXISTS (SELECT 1 FROM entity_instances WHERE entity_instances.id = pull_requests.id AND entity_instances.entity_type = 'pull_request');

-- name: GetProperty :one
SELECT * FROM properties
WHERE entity_id = $1 AND key = $2;
Expand Down
17 changes: 0 additions & 17 deletions database/query/eval_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,3 @@ SELECT s.evaluation_time,
-- name: DeleteEvaluationHistoryByIDs :execrows
DELETE FROM evaluation_statuses s
WHERE s.id = ANY(sqlc.slice(evaluationIds));

-- TemporaryPopulateEvaluationHistory sets the entity_instance_id column for
-- all existing evaluation_rule_entities records to the id of the entity
-- instance that the rule entity is associated with. We derive this from the entity_type
-- and the corresponding entity id (repository_id, pull_request_id, or artifact_id).
-- Note that there are cases where repository_id and pull_request_id will both be set,
-- so we need to rely on the entity_type to determine which one to use. The same
-- applies to repository_id and artifact_id.

-- name: TemporaryPopulateEvaluationHistory :exec
UPDATE evaluation_rule_entities ere
SET entity_instance_id = CASE
WHEN ere.entity_type = 'repository' THEN ere.repository_id
WHEN ere.entity_type = 'pull_request' THEN ere.pull_request_id
WHEN ere.entity_type = 'artifact' THEN ere.artifact_id
END
WHERE entity_instance_id IS NULL;
17 changes: 0 additions & 17 deletions database/query/projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,6 @@ DELETE FROM projects
WHERE id IN (SELECT id FROM get_children)
RETURNING id, name, metadata, created_at, updated_at, parent_id;

-- ListNonOrgProjects is a query that lists all non-organization projects.
-- projects have a boolean field is_organization that is set to true if the project is an organization.
-- this flag is no longer used and will be removed in the future.

-- name: ListNonOrgProjects :many
SELECT * FROM projects
WHERE is_organization = FALSE;

-- ListOrgProjects is a query that lists all organization projects.
-- projects have a boolean field is_organization that is set to true if the project is an organization.
-- this flag is no longer used and will be removed in the future.

-- name: ListOldOrgProjects :many
SELECT * FROM projects
WHERE is_organization = TRUE;


-- OrphanProject is a query that sets the parent_id of a project to NULL.

-- name: OrphanProject :one
Expand Down
35 changes: 0 additions & 35 deletions internal/db/entities.sql.go

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

23 changes: 0 additions & 23 deletions internal/db/eval_history.sql.go

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

80 changes: 0 additions & 80 deletions internal/db/projects.sql.go

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

19 changes: 0 additions & 19 deletions internal/db/querier.go

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

Loading