Skip to content

Commit 9b685a1

Browse files
committed
feat: remove legacy project columns, old settings tables, and app_id defaults
Drop deprecated columns (live_deployment_id, is_rolled_back, depot_project_id) from projects table. Delete environment_build_settings and environment_runtime_settings tables/queries in favor of app-scoped equivalents. Remove DEFAULT '' from app_id columns. Migrate all Go code to use app-scoped queries: github_webhook, verify_handler, deployment_state, build, seed files.
1 parent a8265b1 commit 9b685a1

File tree

81 files changed

+518
-1214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+518
-1214
lines changed

cmd/dev/seed/local.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
6565
projectID := uid.New(uid.ProjectPrefix)
6666
projectSlug := fmt.Sprintf("%s-api", slug)
6767
projectName := fmt.Sprintf("%s API", titleCase)
68+
appID := uid.New(uid.AppPrefix)
6869
rootWorkspaceID := "ws_unkey"
6970
rootKeySpaceID := fmt.Sprintf("ks_%s_root_keys", slug)
7071
rootApiID := "api_unkey"
@@ -129,6 +130,22 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
129130
return fmt.Errorf("failed to create project: %w", err)
130131
}
131132

133+
err = db.Query.InsertApp(ctx, tx, db.InsertAppParams{
134+
ID: appID,
135+
WorkspaceID: workspaceID,
136+
ProjectID: projectID,
137+
Name: projectName,
138+
Slug: "default",
139+
LiveDeploymentID: sql.NullString{},
140+
DepotProjectID: sql.NullString{},
141+
DeleteProtection: sql.NullBool{Valid: false, Bool: false},
142+
CreatedAt: now,
143+
UpdatedAt: sql.NullInt64{Valid: false, Int64: 0},
144+
})
145+
if err != nil {
146+
return fmt.Errorf("failed to create default app: %w", err)
147+
}
148+
132149
err = db.BulkQuery.InsertEnvironments(ctx, tx, []db.InsertEnvironmentParams{
133150
{
134151
ID: previewEnvID,
@@ -153,9 +170,10 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
153170
}
154171

155172
// Create default runtime settings for each environment
156-
err = db.BulkQuery.UpsertEnvironmentRuntimeSettings(ctx, tx, []db.UpsertEnvironmentRuntimeSettingsParams{
173+
err = db.BulkQuery.UpsertAppRuntimeSettings(ctx, tx, []db.UpsertAppRuntimeSettingsParams{
157174
{
158175
WorkspaceID: workspaceID,
176+
AppID: appID,
159177
EnvironmentID: previewEnvID,
160178
Port: 8080,
161179
CpuMillicores: 256,
@@ -164,12 +182,13 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
164182
Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false},
165183
RegionConfig: dbtype.RegionConfig{},
166184
SentinelConfig: []byte{},
167-
ShutdownSignal: db.EnvironmentRuntimeSettingsShutdownSignalSIGTERM,
185+
ShutdownSignal: db.AppRuntimeSettingsShutdownSignalSIGTERM,
168186
CreatedAt: now,
169187
UpdatedAt: sql.NullInt64{Valid: true, Int64: now},
170188
},
171189
{
172190
WorkspaceID: workspaceID,
191+
AppID: appID,
173192
EnvironmentID: productionEnvID,
174193
Port: 8080,
175194
CpuMillicores: 256,
@@ -178,7 +197,7 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
178197
Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false},
179198
RegionConfig: dbtype.RegionConfig{},
180199
SentinelConfig: []byte{},
181-
ShutdownSignal: db.EnvironmentRuntimeSettingsShutdownSignalSIGTERM,
200+
ShutdownSignal: db.AppRuntimeSettingsShutdownSignalSIGTERM,
182201
CreatedAt: now,
183202
UpdatedAt: sql.NullInt64{Valid: true, Int64: now},
184203
},
@@ -188,9 +207,10 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
188207
}
189208

190209
// Create default build settings for each environment
191-
err = db.BulkQuery.UpsertEnvironmentBuildSettings(ctx, tx, []db.UpsertEnvironmentBuildSettingsParams{
210+
err = db.BulkQuery.UpsertAppBuildSettings(ctx, tx, []db.UpsertAppBuildSettingsParams{
192211
{
193212
WorkspaceID: workspaceID,
213+
AppID: appID,
194214
EnvironmentID: previewEnvID,
195215
Dockerfile: "Dockerfile",
196216
DockerContext: ".",
@@ -199,6 +219,7 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error {
199219
},
200220
{
201221
WorkspaceID: workspaceID,
222+
AppID: appID,
202223
EnvironmentID: productionEnvID,
203224
Dockerfile: "Dockerfile",
204225
DockerContext: ".",

pkg/db/BUILD.bazel

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ go_library(
3737
"app_runtime_settings_find.sql_generated.go",
3838
"app_runtime_settings_upsert.sql_generated.go",
3939
"app_update_deployments.sql_generated.go",
40+
"app_update_depot_id.sql_generated.go",
4041
"audit_log_find_target_by_id.sql_generated.go",
4142
"audit_log_insert.sql_generated.go",
4243
"audit_log_target_insert.sql_generated.go",
@@ -57,9 +58,7 @@ go_library(
5758
"bulk_deployment_insert.sql_generated.go",
5859
"bulk_deployment_step_insert.sql_generated.go",
5960
"bulk_deployment_topology_insert.sql_generated.go",
60-
"bulk_environment_build_settings_upsert.sql_generated.go",
6161
"bulk_environment_insert.sql_generated.go",
62-
"bulk_environment_runtime_settings_upsert.sql_generated.go",
6362
"bulk_environment_upsert.sql_generated.go",
6463
"bulk_github_repo_connection_insert.sql_generated.go",
6564
"bulk_identity_insert.sql_generated.go",
@@ -118,6 +117,7 @@ go_library(
118117
"deployment_delete_instances.sql_generated.go",
119118
"deployment_find_by_id.sql_generated.go",
120119
"deployment_find_by_k8s_name.sql_generated.go",
120+
"deployment_find_latest_ready_by_app_and_env.sql_generated.go",
121121
"deployment_insert.sql_generated.go",
122122
"deployment_list_by_environment_id_and_status.sql_generated.go",
123123
"deployment_step_end.sql_generated.go",
@@ -134,15 +134,10 @@ go_library(
134134
"deployment_update_openapi_spec.sql_generated.go",
135135
"deployment_update_status.sql_generated.go",
136136
"doc.go",
137-
"environment_build_settings_find_by_environment_id.sql_generated.go",
138-
"environment_build_settings_upsert.sql_generated.go",
139137
"environment_find_by_id.sql_generated.go",
140138
"environment_find_by_project_id_and_slug.sql_generated.go",
141-
"environment_find_with_settings.sql_generated.go",
142139
"environment_insert.sql_generated.go",
143140
"environment_list_preview.sql_generated.go",
144-
"environment_runtime_settings_find_by_environment_id.sql_generated.go",
145-
"environment_runtime_settings_upsert.sql_generated.go",
146141
"environment_upsert.sql_generated.go",
147142
"environment_variables_find_by_environment_id.sql_generated.go",
148143
"frontline_route_delete_by_fqdn.sql_generated.go",
@@ -245,8 +240,6 @@ go_library(
245240
"project_find_by_id.sql_generated.go",
246241
"project_find_by_workspace_slug.sql_generated.go",
247242
"project_insert.sql_generated.go",
248-
"project_update_deployments.sql_generated.go",
249-
"project_update_depot_id.sql_generated.go",
250243
"querier_bulk_generated.go",
251244
"querier_generated.go",
252245
"queries.go",

pkg/db/app_find_by_id.sql_generated.go

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

pkg/db/app_find_by_project_and_slug.sql_generated.go

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

pkg/db/app_find_with_settings.sql_generated.go

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

pkg/db/app_insert.sql_generated.go

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

pkg/db/app_list_by_project.sql_generated.go

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

pkg/db/app_update_deployments.sql_generated.go

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

pkg/db/app_update_depot_id.sql_generated.go

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

pkg/db/bulk_app_insert.sql_generated.go

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

0 commit comments

Comments
 (0)