Skip to content

Commit

Permalink
Capture latest ent schema state in migration file + applying atlas mi…
Browse files Browse the repository at this point in the history
…gration on staging environment
  • Loading branch information
james03160927 committed May 26, 2024
1 parent 8407617 commit 4f275aa
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
26 changes: 26 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ steps:
# push container image
- name: "gcr.io/cloud-builders/docker"
args: ["push", "us-central1-docker.pkg.dev/dreamboothy/registry-backend/registry-backend-image:$SHORT_SHA"]

# Fetch the database connection string secret for staging
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
entrypoint: "bash"
args:
- "-c"
- |
STAGING_SUPABASE_CONNECTION_STRING=$(gcloud secrets versions access latest --secret=STAGING_SUPABASE_CONNECTION_STRING)
export STAGING_SUPABASE_CONNECTION_STRING=$STAGING_SUPABASE_CONNECTION_STRING
# Install Atlas
- name: 'gcr.io/cloud-builders/curl'
entrypoint: 'sh'
args:
- '-c'
- |
curl -sSL https://atlasgo.sh | sh
# Run database migrations on staging environment
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:latest'
entrypoint: 'bash'
args:
- '-c'
- |
atlas migrate apply --dir "ent/migrate/migrations" --url "$STAGING_SUPABASE_CONNECTION_STRING"
# Publish the release
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:458.0.1'
entrypoint: 'bash'
Expand Down
26 changes: 26 additions & 0 deletions ent/migrate/migrations/20240526144817_migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Create "git_commits" table
CREATE TABLE "git_commits" ("id" uuid NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "commit_hash" text NOT NULL, "branch_name" text NOT NULL, "repo_name" text NOT NULL, "commit_message" text NOT NULL, "commit_timestamp" timestamptz NOT NULL, "author" text NULL, "timestamp" timestamptz NULL, PRIMARY KEY ("id"));
-- Create index "gitcommit_repo_name_commit_hash" to table: "git_commits"
CREATE UNIQUE INDEX "gitcommit_repo_name_commit_hash" ON "git_commits" ("repo_name", "commit_hash");
-- Create "storage_files" table
CREATE TABLE "storage_files" ("id" uuid NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "bucket_name" text NOT NULL, "object_name" text NULL, "file_path" text NOT NULL, "file_type" text NOT NULL, "file_url" text NULL, PRIMARY KEY ("id"));
-- Create "ci_workflow_results" table
CREATE TABLE "ci_workflow_results" ("id" uuid NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "operating_system" text NOT NULL, "gpu_type" text NULL, "pytorch_version" text NULL, "workflow_name" text NULL, "run_id" text NULL, "status" text NULL, "start_time" bigint NULL, "end_time" bigint NULL, "ci_workflow_result_storage_file" uuid NULL, "git_commit_results" uuid NULL, PRIMARY KEY ("id"), CONSTRAINT "ci_workflow_results_git_commits_results" FOREIGN KEY ("git_commit_results") REFERENCES "git_commits" ("id") ON UPDATE NO ACTION ON DELETE SET NULL, CONSTRAINT "ci_workflow_results_storage_files_storage_file" FOREIGN KEY ("ci_workflow_result_storage_file") REFERENCES "storage_files" ("id") ON UPDATE NO ACTION ON DELETE SET NULL);
-- Create "publishers" table
CREATE TABLE "publishers" ("id" text NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "name" text NOT NULL, "description" text NULL, "website" text NULL, "support_email" text NULL, "source_code_repo" text NULL, "logo_url" text NULL, PRIMARY KEY ("id"));
-- Create "nodes" table
CREATE TABLE "nodes" ("id" text NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "name" text NOT NULL, "description" text NULL, "author" text NULL, "license" text NOT NULL, "repository_url" text NOT NULL, "icon_url" text NULL, "tags" text NOT NULL, "publisher_id" text NOT NULL, PRIMARY KEY ("id"), CONSTRAINT "nodes_publishers_nodes" FOREIGN KEY ("publisher_id") REFERENCES "publishers" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION);
-- Create "node_versions" table
CREATE TABLE "node_versions" ("id" uuid NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "version" text NOT NULL, "changelog" text NULL, "pip_dependencies" text NOT NULL, "deprecated" boolean NOT NULL DEFAULT false, "node_id" text NOT NULL, "node_version_storage_file" uuid NULL, PRIMARY KEY ("id"), CONSTRAINT "node_versions_nodes_versions" FOREIGN KEY ("node_id") REFERENCES "nodes" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "node_versions_storage_files_storage_file" FOREIGN KEY ("node_version_storage_file") REFERENCES "storage_files" ("id") ON UPDATE NO ACTION ON DELETE SET NULL);
-- Create index "nodeversion_node_id_version" to table: "node_versions"
CREATE UNIQUE INDEX "nodeversion_node_id_version" ON "node_versions" ("node_id", "version");
-- Create "personal_access_tokens" table
CREATE TABLE "personal_access_tokens" ("id" uuid NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "name" text NOT NULL, "description" text NOT NULL, "token" text NOT NULL, "publisher_id" text NOT NULL, PRIMARY KEY ("id"), CONSTRAINT "personal_access_tokens_publishers_personal_access_tokens" FOREIGN KEY ("publisher_id") REFERENCES "publishers" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION);
-- Create index "personal_access_tokens_token_key" to table: "personal_access_tokens"
CREATE UNIQUE INDEX "personal_access_tokens_token_key" ON "personal_access_tokens" ("token");
-- Create index "personalaccesstoken_token" to table: "personal_access_tokens"
CREATE UNIQUE INDEX "personalaccesstoken_token" ON "personal_access_tokens" ("token");
-- Create "users" table
CREATE TABLE "users" ("id" character varying NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT NULL, "email" character varying NULL, "name" character varying NULL, "is_approved" boolean NOT NULL DEFAULT false, "is_admin" boolean NOT NULL DEFAULT false, PRIMARY KEY ("id"));
-- Create "publisher_permissions" table
CREATE TABLE "publisher_permissions" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "permission" character varying NOT NULL, "publisher_id" text NOT NULL, "user_id" character varying NOT NULL, PRIMARY KEY ("id"), CONSTRAINT "publisher_permissions_publishers_publisher_permissions" FOREIGN KEY ("publisher_id") REFERENCES "publishers" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "publisher_permissions_users_publisher_permissions" FOREIGN KEY ("user_id") REFERENCES "users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION);
2 changes: 2 additions & 0 deletions ent/migrate/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:y3z5P4GWPQWBraiBTLgj3b1AGznQ3rQfzxhn9/WnFdw=
20240526144817_migration.sql h1:Rc0HHsjtSJsJHNAj6pI3oINZE4aCcDRk2P95IB4yUys=
16 changes: 7 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package main

import (
"context"
"fmt"
"os"
"registry-backend/config"
"registry-backend/ent"
"registry-backend/ent/migrate"
drip_logging "registry-backend/logging"
"registry-backend/server"

Expand Down Expand Up @@ -39,13 +37,13 @@ func main() {
}
defer client.Close()
// Run the auto migration tool for localdev.
if os.Getenv("DRIP_ENV") == "localdev" || os.Getenv("DRIP_ENV") == "staging" {
log.Info().Msg("Running migrations")
if err := client.Schema.Create(context.Background(), migrate.WithDropIndex(true),
migrate.WithDropColumn(true)); err != nil {
log.Fatal().Err(err).Msg("failed creating schema resources.")
}
}
//if os.Getenv("DRIP_ENV") == "localdev" || os.Getenv("DRIP_ENV") == "staging" {
// log.Info().Msg("Running migrations")
// if err := client.Schema.Create(context.Background(), migrate.WithDropIndex(true),
// migrate.WithDropColumn(true)); err != nil {
// log.Fatal().Err(err).Msg("failed creating schema resources.")
// }
//}

server := server.NewServer(client, &config)
server.Start()
Expand Down

0 comments on commit 4f275aa

Please sign in to comment.