Skip to content

Commit 58817ff

Browse files
committed
feat: add app_id to github_repo_connections for app-scoped repo linking
Each app now has its own GitHub repo connection (UNIQUE(app_id)) instead of one connection per project. Drizzle relations updated accordingly: apps.githubRepoConnection (one), projects.githubRepoConnections (many).
1 parent 86a248d commit 58817ff

10 files changed

+39
-57
lines changed

pkg/db/bulk_github_repo_connection_insert.sql_generated.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/github_repo_connection_insert.sql_generated.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/github_repo_connection_list.sql_generated.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/models_generated.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/queries/github_repo_connection_insert.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- name: InsertGithubRepoConnection :exec
22
INSERT INTO github_repo_connections (
33
project_id,
4+
app_id,
45
installation_id,
56
repository_id,
67
repository_full_name,
@@ -9,6 +10,7 @@ INSERT INTO github_repo_connections (
910
)
1011
VALUES (
1112
sqlc.arg(project_id),
13+
sqlc.arg(app_id),
1214
sqlc.arg(installation_id),
1315
sqlc.arg(repository_id),
1416
sqlc.arg(repository_full_name),

pkg/db/queries/github_repo_connection_list.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
SELECT
33
pk,
44
project_id,
5+
app_id,
56
installation_id,
67
repository_id,
78
repository_full_name,

pkg/db/schema.sql

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -379,36 +379,6 @@ CREATE TABLE `environment_variables` (
379379
CONSTRAINT `environment_id_key` UNIQUE(`environment_id`,`key`)
380380
);
381381

382-
CREATE TABLE `environment_build_settings` (
383-
`pk` bigint unsigned AUTO_INCREMENT NOT NULL,
384-
`workspace_id` varchar(256) NOT NULL,
385-
`environment_id` varchar(128) NOT NULL,
386-
`dockerfile` varchar(500) NOT NULL DEFAULT 'Dockerfile',
387-
`docker_context` varchar(500) NOT NULL DEFAULT '.',
388-
`created_at` bigint NOT NULL,
389-
`updated_at` bigint,
390-
CONSTRAINT `environment_build_settings_pk` PRIMARY KEY(`pk`),
391-
CONSTRAINT `env_build_settings_environment_id_idx` UNIQUE(`environment_id`)
392-
);
393-
394-
CREATE TABLE `environment_runtime_settings` (
395-
`pk` bigint unsigned AUTO_INCREMENT NOT NULL,
396-
`workspace_id` varchar(256) NOT NULL,
397-
`environment_id` varchar(128) NOT NULL,
398-
`port` int NOT NULL DEFAULT 8080,
399-
`cpu_millicores` int NOT NULL DEFAULT 256,
400-
`memory_mib` int NOT NULL DEFAULT 256,
401-
`command` json NOT NULL DEFAULT ('[]'),
402-
`healthcheck` json,
403-
`region_config` json NOT NULL DEFAULT ('{}'),
404-
`shutdown_signal` enum('SIGTERM','SIGINT','SIGQUIT','SIGKILL') NOT NULL DEFAULT 'SIGTERM',
405-
`sentinel_config` longblob NOT NULL,
406-
`created_at` bigint NOT NULL,
407-
`updated_at` bigint,
408-
CONSTRAINT `environment_runtime_settings_pk` PRIMARY KEY(`pk`),
409-
CONSTRAINT `env_runtime_settings_environment_id_idx` UNIQUE(`environment_id`)
410-
);
411-
412382
CREATE TABLE `clickhouse_workspace_settings` (
413383
`pk` bigint unsigned AUTO_INCREMENT NOT NULL,
414384
`workspace_id` varchar(256) NOT NULL,
@@ -433,10 +403,7 @@ CREATE TABLE `projects` (
433403
`workspace_id` varchar(256) NOT NULL,
434404
`name` varchar(256) NOT NULL,
435405
`slug` varchar(256) NOT NULL,
436-
`live_deployment_id` varchar(256),
437-
`is_rolled_back` boolean NOT NULL DEFAULT false,
438406
`default_branch` varchar(256) DEFAULT 'main',
439-
`depot_project_id` varchar(255),
440407
`delete_protection` boolean DEFAULT false,
441408
`created_at` bigint NOT NULL,
442409
`updated_at` bigint,
@@ -538,7 +505,7 @@ CREATE TABLE `deployments` (
538505
`workspace_id` varchar(256) NOT NULL,
539506
`project_id` varchar(256) NOT NULL,
540507
`environment_id` varchar(128) NOT NULL,
541-
`app_id` varchar(64) NOT NULL DEFAULT '',
508+
`app_id` varchar(64) NOT NULL,
542509
`image` varchar(256),
543510
`build_id` varchar(128),
544511
`git_commit_sha` varchar(40),
@@ -572,7 +539,7 @@ CREATE TABLE `deployment_steps` (
572539
`project_id` varchar(128) NOT NULL,
573540
`environment_id` varchar(128) NOT NULL,
574541
`deployment_id` varchar(128) NOT NULL,
575-
`app_id` varchar(64) NOT NULL DEFAULT '',
542+
`app_id` varchar(64) NOT NULL,
576543
`step` enum('queued','building','deploying','network') NOT NULL DEFAULT 'queued',
577544
`started_at` bigint unsigned NOT NULL,
578545
`ended_at` bigint unsigned,
@@ -681,7 +648,7 @@ CREATE TABLE `instances` (
681648
`deployment_id` varchar(255) NOT NULL,
682649
`workspace_id` varchar(255) NOT NULL,
683650
`project_id` varchar(255) NOT NULL,
684-
`app_id` varchar(64) NOT NULL DEFAULT '',
651+
`app_id` varchar(64) NOT NULL,
685652
`region` varchar(64) NOT NULL,
686653
`k8s_name` varchar(255) NOT NULL,
687654
`address` varchar(255) NOT NULL,
@@ -712,7 +679,7 @@ CREATE TABLE `frontline_routes` (
712679
`pk` bigint unsigned AUTO_INCREMENT NOT NULL,
713680
`id` varchar(128) NOT NULL,
714681
`project_id` varchar(255) NOT NULL,
715-
`app_id` varchar(64) NOT NULL DEFAULT '',
682+
`app_id` varchar(64) NOT NULL,
716683
`deployment_id` varchar(255) NOT NULL,
717684
`environment_id` varchar(255) NOT NULL,
718685
`fully_qualified_domain_name` varchar(256) NOT NULL,
@@ -737,21 +704,22 @@ CREATE TABLE `github_app_installations` (
737704
CREATE TABLE `github_repo_connections` (
738705
`pk` bigint unsigned AUTO_INCREMENT NOT NULL,
739706
`project_id` varchar(64) NOT NULL,
707+
`app_id` varchar(64) NOT NULL,
740708
`installation_id` bigint NOT NULL,
741709
`repository_id` bigint NOT NULL,
742710
`repository_full_name` varchar(500) NOT NULL,
743711
`created_at` bigint NOT NULL,
744712
`updated_at` bigint,
745713
CONSTRAINT `github_repo_connections_pk` PRIMARY KEY(`pk`),
746-
CONSTRAINT `github_repo_connections_project_id_unique` UNIQUE(`project_id`)
714+
CONSTRAINT `github_repo_connections_app_id_unique` UNIQUE(`app_id`)
747715
);
748716

749717
CREATE TABLE `cilium_network_policies` (
750718
`pk` bigint unsigned AUTO_INCREMENT NOT NULL,
751719
`id` varchar(64) NOT NULL,
752720
`workspace_id` varchar(255) NOT NULL,
753721
`project_id` varchar(255) NOT NULL,
754-
`app_id` varchar(64) NOT NULL DEFAULT '',
722+
`app_id` varchar(64) NOT NULL,
755723
`environment_id` varchar(255) NOT NULL,
756724
`deployment_id` varchar(128) NOT NULL,
757725
`k8s_name` varchar(64) NOT NULL,

web/internal/db/src/schema/apps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { relations } from "drizzle-orm";
22
import { bigint, boolean, index, mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core";
3+
import { githubRepoConnections } from "./github_app";
34
import { deleteProtection } from "./util/delete_protection";
45
import { lifecycleDates } from "./util/lifecycle_dates";
56
import { workspaces } from "./workspaces";
@@ -41,4 +42,8 @@ export const appsRelations = relations(apps, ({ one }) => ({
4142
fields: [apps.projectId],
4243
references: [projects.id],
4344
}),
45+
githubRepoConnection: one(githubRepoConnections, {
46+
fields: [apps.id],
47+
references: [githubRepoConnections.appId],
48+
}),
4449
}));

web/internal/db/src/schema/github_app.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { relations } from "drizzle-orm";
22
import { bigint, index, mysqlTable, varchar } from "drizzle-orm/mysql-core";
3+
import { apps } from "./apps";
34
import { projects } from "./projects";
45
import { lifecycleDates } from "./util/lifecycle_dates";
56
import { workspaces } from "./workspaces";
@@ -22,7 +23,8 @@ export const githubRepoConnections = mysqlTable(
2223
"github_repo_connections",
2324
{
2425
pk: bigint("pk", { mode: "number", unsigned: true }).autoincrement().primaryKey(),
25-
projectId: varchar("project_id", { length: 64 }).notNull().unique(),
26+
projectId: varchar("project_id", { length: 64 }).notNull(),
27+
appId: varchar("app_id", { length: 64 }).notNull().unique(),
2628
installationId: bigint("installation_id", {
2729
mode: "number",
2830
}).notNull(),
@@ -40,6 +42,10 @@ export const githubRepoConnectionsRelations = relations(githubRepoConnections, (
4042
fields: [githubRepoConnections.projectId],
4143
references: [projects.id],
4244
}),
45+
app: one(apps, {
46+
fields: [githubRepoConnections.appId],
47+
references: [apps.id],
48+
}),
4349
installation: one(githubAppInstallations, {
4450
fields: [githubRepoConnections.installationId],
4551
references: [githubAppInstallations.installationId],
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { relations } from "drizzle-orm";
2-
import { bigint, boolean, mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core";
2+
import { bigint, mysqlTable, uniqueIndex, varchar } from "drizzle-orm/mysql-core";
3+
import { apps } from "./apps";
34
import { deleteProtection } from "./util/delete_protection";
45
import { lifecycleDates } from "./util/lifecycle_dates";
56
import { workspaces } from "./workspaces";
@@ -17,12 +18,7 @@ export const projects = mysqlTable(
1718
name: varchar("name", { length: 256 }).notNull(),
1819
slug: varchar("slug", { length: 256 }).notNull(), // URL-safe identifier within workspace
1920

20-
// this is likely temporary but we need a way to point to the current prod deployment.
21-
// in the future I think we want to have a special deployment per environment, but for now this is fine
22-
liveDeploymentId: varchar("live_deployment_id", { length: 256 }),
23-
isRolledBack: boolean("is_rolled_back").notNull().default(false),
2421
defaultBranch: varchar("default_branch", { length: 256 }).default("main"),
25-
depotProjectId: varchar("depot_project_id", { length: 255 }),
2622

2723
...deleteProtection,
2824
...lifecycleDates,
@@ -35,15 +31,8 @@ export const projectsRelations = relations(projects, ({ one, many }) => ({
3531
fields: [projects.workspaceId],
3632
references: [workspaces.id],
3733
}),
34+
apps: many(apps),
3835
deployments: many(deployments),
39-
activeDeployment: one(deployments, {
40-
fields: [projects.liveDeploymentId],
41-
references: [deployments.id],
42-
}),
4336
frontlineRoutes: many(frontlineRoutes),
44-
githubRepoConnection: one(githubRepoConnections, {
45-
fields: [projects.id],
46-
references: [githubRepoConnections.projectId],
47-
}),
48-
// environments: many(projectEnvironments),
37+
githubRepoConnections: many(githubRepoConnections),
4938
}));

0 commit comments

Comments
 (0)