diff --git a/cmd/dev/seed/local.go b/cmd/dev/seed/local.go index 966bc67e29..02dc530b06 100644 --- a/cmd/dev/seed/local.go +++ b/cmd/dev/seed/local.go @@ -131,23 +131,21 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error { err = db.BulkQuery.InsertEnvironments(ctx, tx, []db.InsertEnvironmentParams{ { - ID: previewEnvID, - WorkspaceID: workspaceID, - ProjectID: projectID, - Slug: "preview", - Description: "", - CreatedAt: time.Now().UnixMilli(), - UpdatedAt: sql.NullInt64{Valid: false, Int64: 0}, - SentinelConfig: []byte{}, + ID: previewEnvID, + WorkspaceID: workspaceID, + ProjectID: projectID, + Slug: "preview", + Description: "", + CreatedAt: time.Now().UnixMilli(), + UpdatedAt: sql.NullInt64{Valid: false, Int64: 0}, }, { - ID: productionEnvID, - WorkspaceID: workspaceID, - ProjectID: projectID, - Slug: "production", - Description: "", - CreatedAt: time.Now().UnixMilli(), - UpdatedAt: sql.NullInt64{Valid: false, Int64: 0}, - SentinelConfig: []byte{}, + ID: productionEnvID, + WorkspaceID: workspaceID, + ProjectID: projectID, + Slug: "production", + Description: "", + CreatedAt: time.Now().UnixMilli(), + UpdatedAt: sql.NullInt64{Valid: false, Int64: 0}, }, }) if err != nil { @@ -157,29 +155,29 @@ func seedLocal(ctx context.Context, cmd *cli.Command) error { // Create default runtime settings for each environment err = db.BulkQuery.UpsertEnvironmentRuntimeSettings(ctx, tx, []db.UpsertEnvironmentRuntimeSettingsParams{ { - WorkspaceID: workspaceID, - EnvironmentID: previewEnvID, - Port: 8080, - CpuMillicores: 256, - MemoryMib: 256, - Command: dbtype.StringSlice{}, - Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false}, - RegionConfig: dbtype.RegionConfig{}, - + WorkspaceID: workspaceID, + EnvironmentID: previewEnvID, + Port: 8080, + CpuMillicores: 256, + MemoryMib: 256, + Command: dbtype.StringSlice{}, + Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false}, + RegionConfig: dbtype.RegionConfig{}, + SentinelConfig: []byte{}, ShutdownSignal: db.EnvironmentRuntimeSettingsShutdownSignalSIGTERM, CreatedAt: now, UpdatedAt: sql.NullInt64{Valid: true, Int64: now}, }, { - WorkspaceID: workspaceID, - EnvironmentID: productionEnvID, - Port: 8080, - CpuMillicores: 256, - MemoryMib: 256, - Command: dbtype.StringSlice{}, - Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false}, - RegionConfig: dbtype.RegionConfig{}, - + WorkspaceID: workspaceID, + EnvironmentID: productionEnvID, + Port: 8080, + CpuMillicores: 256, + MemoryMib: 256, + Command: dbtype.StringSlice{}, + Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false}, + RegionConfig: dbtype.RegionConfig{}, + SentinelConfig: []byte{}, ShutdownSignal: db.EnvironmentRuntimeSettingsShutdownSignalSIGTERM, CreatedAt: now, UpdatedAt: sql.NullInt64{Valid: true, Int64: now}, diff --git a/pkg/db/bulk_environment_insert.sql_generated.go b/pkg/db/bulk_environment_insert.sql_generated.go index 5b2688f8da..bf683304d8 100644 --- a/pkg/db/bulk_environment_insert.sql_generated.go +++ b/pkg/db/bulk_environment_insert.sql_generated.go @@ -9,7 +9,7 @@ import ( ) // bulkInsertEnvironment is the base query for bulk insert -const bulkInsertEnvironment = `INSERT INTO environments ( id, workspace_id, project_id, slug, description, created_at, updated_at, sentinel_config ) VALUES %s` +const bulkInsertEnvironment = `INSERT INTO environments ( id, workspace_id, project_id, slug, description, created_at, updated_at ) VALUES %s` // InsertEnvironments performs bulk insert in a single query func (q *BulkQueries) InsertEnvironments(ctx context.Context, db DBTX, args []InsertEnvironmentParams) error { @@ -21,7 +21,7 @@ func (q *BulkQueries) InsertEnvironments(ctx context.Context, db DBTX, args []In // Build the bulk insert query valueClauses := make([]string, len(args)) for i := range args { - valueClauses[i] = "( ?, ?, ?, ?, ?, ?, ?, ? )" + valueClauses[i] = "( ?, ?, ?, ?, ?, ?, ? )" } bulkQuery := fmt.Sprintf(bulkInsertEnvironment, strings.Join(valueClauses, ", ")) @@ -36,7 +36,6 @@ func (q *BulkQueries) InsertEnvironments(ctx context.Context, db DBTX, args []In allArgs = append(allArgs, arg.Description) allArgs = append(allArgs, arg.CreatedAt) allArgs = append(allArgs, arg.UpdatedAt) - allArgs = append(allArgs, arg.SentinelConfig) } // Execute the bulk insert diff --git a/pkg/db/bulk_environment_runtime_settings_upsert.sql_generated.go b/pkg/db/bulk_environment_runtime_settings_upsert.sql_generated.go index e8c7a8d802..d172145b17 100644 --- a/pkg/db/bulk_environment_runtime_settings_upsert.sql_generated.go +++ b/pkg/db/bulk_environment_runtime_settings_upsert.sql_generated.go @@ -9,7 +9,7 @@ import ( ) // bulkUpsertEnvironmentRuntimeSettings is the base query for bulk insert -const bulkUpsertEnvironmentRuntimeSettings = `INSERT INTO environment_runtime_settings ( workspace_id, environment_id, port, cpu_millicores, memory_mib, command, healthcheck, region_config, shutdown_signal, created_at, updated_at ) VALUES %s ON DUPLICATE KEY UPDATE +const bulkUpsertEnvironmentRuntimeSettings = `INSERT INTO environment_runtime_settings ( workspace_id, environment_id, port, cpu_millicores, memory_mib, command, healthcheck, region_config, shutdown_signal, sentinel_config, created_at, updated_at ) VALUES %s ON DUPLICATE KEY UPDATE port = VALUES(port), cpu_millicores = VALUES(cpu_millicores), memory_mib = VALUES(memory_mib), @@ -17,6 +17,7 @@ const bulkUpsertEnvironmentRuntimeSettings = `INSERT INTO environment_runtime_se healthcheck = VALUES(healthcheck), region_config = VALUES(region_config), shutdown_signal = VALUES(shutdown_signal), + sentinel_config = VALUES(sentinel_config), updated_at = VALUES(updated_at)` // UpsertEnvironmentRuntimeSettings performs bulk insert in a single query @@ -29,7 +30,7 @@ func (q *BulkQueries) UpsertEnvironmentRuntimeSettings(ctx context.Context, db D // Build the bulk insert query valueClauses := make([]string, len(args)) for i := range args { - valueClauses[i] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + valueClauses[i] = "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" } bulkQuery := fmt.Sprintf(bulkUpsertEnvironmentRuntimeSettings, strings.Join(valueClauses, ", ")) @@ -46,6 +47,7 @@ func (q *BulkQueries) UpsertEnvironmentRuntimeSettings(ctx context.Context, db D allArgs = append(allArgs, arg.Healthcheck) allArgs = append(allArgs, arg.RegionConfig) allArgs = append(allArgs, arg.ShutdownSignal) + allArgs = append(allArgs, arg.SentinelConfig) allArgs = append(allArgs, arg.CreatedAt) allArgs = append(allArgs, arg.UpdatedAt) } diff --git a/pkg/db/bulk_environment_upsert.sql_generated.go b/pkg/db/bulk_environment_upsert.sql_generated.go index 3438fdc668..13141aca14 100644 --- a/pkg/db/bulk_environment_upsert.sql_generated.go +++ b/pkg/db/bulk_environment_upsert.sql_generated.go @@ -9,7 +9,7 @@ import ( ) // bulkUpsertEnvironment is the base query for bulk insert -const bulkUpsertEnvironment = `INSERT INTO environments ( id, workspace_id, project_id, slug, sentinel_config, created_at ) VALUES %s ON DUPLICATE KEY UPDATE slug = VALUES(slug)` +const bulkUpsertEnvironment = `INSERT INTO environments ( id, workspace_id, project_id, slug, created_at ) VALUES %s ON DUPLICATE KEY UPDATE slug = VALUES(slug)` // UpsertEnvironment performs bulk insert in a single query func (q *BulkQueries) UpsertEnvironment(ctx context.Context, db DBTX, args []UpsertEnvironmentParams) error { @@ -21,7 +21,7 @@ func (q *BulkQueries) UpsertEnvironment(ctx context.Context, db DBTX, args []Ups // Build the bulk insert query valueClauses := make([]string, len(args)) for i := range args { - valueClauses[i] = "(?, ?, ?, ?, ?, ?)" + valueClauses[i] = "(?, ?, ?, ?, ?)" } bulkQuery := fmt.Sprintf(bulkUpsertEnvironment, strings.Join(valueClauses, ", ")) @@ -33,7 +33,6 @@ func (q *BulkQueries) UpsertEnvironment(ctx context.Context, db DBTX, args []Ups allArgs = append(allArgs, arg.WorkspaceID) allArgs = append(allArgs, arg.ProjectID) allArgs = append(allArgs, arg.Slug) - allArgs = append(allArgs, arg.SentinelConfig) allArgs = append(allArgs, arg.CreatedAt) } diff --git a/pkg/db/environment_find_by_project_id_and_slug.sql_generated.go b/pkg/db/environment_find_by_project_id_and_slug.sql_generated.go index aa38eb7817..71901325b8 100644 --- a/pkg/db/environment_find_by_project_id_and_slug.sql_generated.go +++ b/pkg/db/environment_find_by_project_id_and_slug.sql_generated.go @@ -10,7 +10,7 @@ import ( ) const findEnvironmentByProjectIdAndSlug = `-- name: FindEnvironmentByProjectIdAndSlug :one -SELECT pk, id, workspace_id, project_id, slug, description, sentinel_config, delete_protection, created_at, updated_at +SELECT pk, id, workspace_id, project_id, slug, description, delete_protection, created_at, updated_at FROM environments WHERE workspace_id = ? AND project_id = ? @@ -25,7 +25,7 @@ type FindEnvironmentByProjectIdAndSlugParams struct { // FindEnvironmentByProjectIdAndSlug // -// SELECT pk, id, workspace_id, project_id, slug, description, sentinel_config, delete_protection, created_at, updated_at +// SELECT pk, id, workspace_id, project_id, slug, description, delete_protection, created_at, updated_at // FROM environments // WHERE workspace_id = ? // AND project_id = ? @@ -40,7 +40,6 @@ func (q *Queries) FindEnvironmentByProjectIdAndSlug(ctx context.Context, db DBTX &i.ProjectID, &i.Slug, &i.Description, - &i.SentinelConfig, &i.DeleteProtection, &i.CreatedAt, &i.UpdatedAt, diff --git a/pkg/db/environment_find_with_settings.sql_generated.go b/pkg/db/environment_find_with_settings.sql_generated.go index 6487c9f57c..34ba22f453 100644 --- a/pkg/db/environment_find_with_settings.sql_generated.go +++ b/pkg/db/environment_find_with_settings.sql_generated.go @@ -11,7 +11,7 @@ import ( const findEnvironmentWithSettingsByProjectIdAndSlug = `-- name: FindEnvironmentWithSettingsByProjectIdAndSlug :one SELECT - e.pk, e.id, e.workspace_id, e.project_id, e.slug, e.description, e.sentinel_config, e.delete_protection, e.created_at, e.updated_at, + e.pk, e.id, e.workspace_id, e.project_id, e.slug, e.description, e.delete_protection, e.created_at, e.updated_at, ebs.pk, ebs.workspace_id, ebs.environment_id, ebs.dockerfile, ebs.docker_context, ebs.created_at, ebs.updated_at, ers.pk, ers.workspace_id, ers.environment_id, ers.port, ers.cpu_millicores, ers.memory_mib, ers.command, ers.healthcheck, ers.region_config, ers.shutdown_signal, ers.sentinel_config, ers.created_at, ers.updated_at FROM environments e @@ -37,7 +37,7 @@ type FindEnvironmentWithSettingsByProjectIdAndSlugRow struct { // FindEnvironmentWithSettingsByProjectIdAndSlug // // SELECT -// e.pk, e.id, e.workspace_id, e.project_id, e.slug, e.description, e.sentinel_config, e.delete_protection, e.created_at, e.updated_at, +// e.pk, e.id, e.workspace_id, e.project_id, e.slug, e.description, e.delete_protection, e.created_at, e.updated_at, // ebs.pk, ebs.workspace_id, ebs.environment_id, ebs.dockerfile, ebs.docker_context, ebs.created_at, ebs.updated_at, // ers.pk, ers.workspace_id, ers.environment_id, ers.port, ers.cpu_millicores, ers.memory_mib, ers.command, ers.healthcheck, ers.region_config, ers.shutdown_signal, ers.sentinel_config, ers.created_at, ers.updated_at // FROM environments e @@ -56,7 +56,6 @@ func (q *Queries) FindEnvironmentWithSettingsByProjectIdAndSlug(ctx context.Cont &i.Environment.ProjectID, &i.Environment.Slug, &i.Environment.Description, - &i.Environment.SentinelConfig, &i.Environment.DeleteProtection, &i.Environment.CreatedAt, &i.Environment.UpdatedAt, diff --git a/pkg/db/environment_insert.sql_generated.go b/pkg/db/environment_insert.sql_generated.go index fdecffdf2c..29cd1eb696 100644 --- a/pkg/db/environment_insert.sql_generated.go +++ b/pkg/db/environment_insert.sql_generated.go @@ -18,22 +18,20 @@ INSERT INTO environments ( slug, description, created_at, - updated_at, - sentinel_config + updated_at ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ? ) ` type InsertEnvironmentParams struct { - ID string `db:"id"` - WorkspaceID string `db:"workspace_id"` - ProjectID string `db:"project_id"` - Slug string `db:"slug"` - Description string `db:"description"` - CreatedAt int64 `db:"created_at"` - UpdatedAt sql.NullInt64 `db:"updated_at"` - SentinelConfig []byte `db:"sentinel_config"` + ID string `db:"id"` + WorkspaceID string `db:"workspace_id"` + ProjectID string `db:"project_id"` + Slug string `db:"slug"` + Description string `db:"description"` + CreatedAt int64 `db:"created_at"` + UpdatedAt sql.NullInt64 `db:"updated_at"` } // InsertEnvironment @@ -45,10 +43,9 @@ type InsertEnvironmentParams struct { // slug, // description, // created_at, -// updated_at, -// sentinel_config +// updated_at // ) VALUES ( -// ?, ?, ?, ?, ?, ?, ?, ? +// ?, ?, ?, ?, ?, ?, ? // ) func (q *Queries) InsertEnvironment(ctx context.Context, db DBTX, arg InsertEnvironmentParams) error { _, err := db.ExecContext(ctx, insertEnvironment, @@ -59,7 +56,6 @@ func (q *Queries) InsertEnvironment(ctx context.Context, db DBTX, arg InsertEnvi arg.Description, arg.CreatedAt, arg.UpdatedAt, - arg.SentinelConfig, ) return err } diff --git a/pkg/db/environment_list_preview.sql_generated.go b/pkg/db/environment_list_preview.sql_generated.go index 980a524973..7ced31ad1d 100644 --- a/pkg/db/environment_list_preview.sql_generated.go +++ b/pkg/db/environment_list_preview.sql_generated.go @@ -10,7 +10,7 @@ import ( ) const listPreviewEnvironments = `-- name: ListPreviewEnvironments :many -SELECT pk, id, workspace_id, project_id, slug, description, sentinel_config, delete_protection, created_at, updated_at +SELECT pk, id, workspace_id, project_id, slug, description, delete_protection, created_at, updated_at FROM environments WHERE slug = 'preview' AND pk > ? @@ -25,7 +25,7 @@ type ListPreviewEnvironmentsParams struct { // ListPreviewEnvironments // -// SELECT pk, id, workspace_id, project_id, slug, description, sentinel_config, delete_protection, created_at, updated_at +// SELECT pk, id, workspace_id, project_id, slug, description, delete_protection, created_at, updated_at // FROM environments // WHERE slug = 'preview' // AND pk > ? @@ -47,7 +47,6 @@ func (q *Queries) ListPreviewEnvironments(ctx context.Context, db DBTX, arg List &i.ProjectID, &i.Slug, &i.Description, - &i.SentinelConfig, &i.DeleteProtection, &i.CreatedAt, &i.UpdatedAt, diff --git a/pkg/db/environment_runtime_settings_upsert.sql_generated.go b/pkg/db/environment_runtime_settings_upsert.sql_generated.go index 6bc361088a..aa07885a50 100644 --- a/pkg/db/environment_runtime_settings_upsert.sql_generated.go +++ b/pkg/db/environment_runtime_settings_upsert.sql_generated.go @@ -23,9 +23,10 @@ INSERT INTO environment_runtime_settings ( healthcheck, region_config, shutdown_signal, + sentinel_config, created_at, updated_at -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE port = VALUES(port), cpu_millicores = VALUES(cpu_millicores), @@ -34,6 +35,7 @@ ON DUPLICATE KEY UPDATE healthcheck = VALUES(healthcheck), region_config = VALUES(region_config), shutdown_signal = VALUES(shutdown_signal), + sentinel_config = VALUES(sentinel_config), updated_at = VALUES(updated_at) ` @@ -47,6 +49,7 @@ type UpsertEnvironmentRuntimeSettingsParams struct { Healthcheck dbtype.NullHealthcheck `db:"healthcheck"` RegionConfig dbtype.RegionConfig `db:"region_config"` ShutdownSignal EnvironmentRuntimeSettingsShutdownSignal `db:"shutdown_signal"` + SentinelConfig []byte `db:"sentinel_config"` CreatedAt int64 `db:"created_at"` UpdatedAt sql.NullInt64 `db:"updated_at"` } @@ -63,9 +66,10 @@ type UpsertEnvironmentRuntimeSettingsParams struct { // healthcheck, // region_config, // shutdown_signal, +// sentinel_config, // created_at, // updated_at -// ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +// ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) // ON DUPLICATE KEY UPDATE // port = VALUES(port), // cpu_millicores = VALUES(cpu_millicores), @@ -74,6 +78,7 @@ type UpsertEnvironmentRuntimeSettingsParams struct { // healthcheck = VALUES(healthcheck), // region_config = VALUES(region_config), // shutdown_signal = VALUES(shutdown_signal), +// sentinel_config = VALUES(sentinel_config), // updated_at = VALUES(updated_at) func (q *Queries) UpsertEnvironmentRuntimeSettings(ctx context.Context, db DBTX, arg UpsertEnvironmentRuntimeSettingsParams) error { _, err := db.ExecContext(ctx, upsertEnvironmentRuntimeSettings, @@ -86,6 +91,7 @@ func (q *Queries) UpsertEnvironmentRuntimeSettings(ctx context.Context, db DBTX, arg.Healthcheck, arg.RegionConfig, arg.ShutdownSignal, + arg.SentinelConfig, arg.CreatedAt, arg.UpdatedAt, ) diff --git a/pkg/db/environment_upsert.sql_generated.go b/pkg/db/environment_upsert.sql_generated.go index cdfdc025c5..caaabf2a25 100644 --- a/pkg/db/environment_upsert.sql_generated.go +++ b/pkg/db/environment_upsert.sql_generated.go @@ -15,19 +15,17 @@ INSERT INTO environments ( workspace_id, project_id, slug, - sentinel_config, created_at -) VALUES (?, ?, ?, ?, ?, ?) +) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE slug = VALUES(slug) ` type UpsertEnvironmentParams struct { - ID string `db:"id"` - WorkspaceID string `db:"workspace_id"` - ProjectID string `db:"project_id"` - Slug string `db:"slug"` - SentinelConfig []byte `db:"sentinel_config"` - CreatedAt int64 `db:"created_at"` + ID string `db:"id"` + WorkspaceID string `db:"workspace_id"` + ProjectID string `db:"project_id"` + Slug string `db:"slug"` + CreatedAt int64 `db:"created_at"` } // UpsertEnvironment @@ -37,9 +35,8 @@ type UpsertEnvironmentParams struct { // workspace_id, // project_id, // slug, -// sentinel_config, // created_at -// ) VALUES (?, ?, ?, ?, ?, ?) +// ) VALUES (?, ?, ?, ?, ?) // ON DUPLICATE KEY UPDATE slug = VALUES(slug) func (q *Queries) UpsertEnvironment(ctx context.Context, db DBTX, arg UpsertEnvironmentParams) error { _, err := db.ExecContext(ctx, upsertEnvironment, @@ -47,7 +44,6 @@ func (q *Queries) UpsertEnvironment(ctx context.Context, db DBTX, arg UpsertEnvi arg.WorkspaceID, arg.ProjectID, arg.Slug, - arg.SentinelConfig, arg.CreatedAt, ) return err diff --git a/pkg/db/models_generated.go b/pkg/db/models_generated.go index 4909b8369c..2cf3b186a1 100644 --- a/pkg/db/models_generated.go +++ b/pkg/db/models_generated.go @@ -1136,7 +1136,6 @@ type Environment struct { ProjectID string `db:"project_id"` Slug string `db:"slug"` Description string `db:"description"` - SentinelConfig []byte `db:"sentinel_config"` DeleteProtection sql.NullBool `db:"delete_protection"` CreatedAt int64 `db:"created_at"` UpdatedAt sql.NullInt64 `db:"updated_at"` @@ -1163,7 +1162,7 @@ type EnvironmentRuntimeSetting struct { Healthcheck dbtype.NullHealthcheck `db:"healthcheck"` RegionConfig dbtype.RegionConfig `db:"region_config"` ShutdownSignal EnvironmentRuntimeSettingsShutdownSignal `db:"shutdown_signal"` - SentinelConfig sql.NullString `db:"sentinel_config"` + SentinelConfig []byte `db:"sentinel_config"` CreatedAt int64 `db:"created_at"` UpdatedAt sql.NullInt64 `db:"updated_at"` } diff --git a/pkg/db/querier_generated.go b/pkg/db/querier_generated.go index 82d4c0b90a..2c4f70b650 100644 --- a/pkg/db/querier_generated.go +++ b/pkg/db/querier_generated.go @@ -293,7 +293,7 @@ type Querier interface { FindEnvironmentById(ctx context.Context, db DBTX, id string) (FindEnvironmentByIdRow, error) //FindEnvironmentByProjectIdAndSlug // - // SELECT pk, id, workspace_id, project_id, slug, description, sentinel_config, delete_protection, created_at, updated_at + // SELECT pk, id, workspace_id, project_id, slug, description, delete_protection, created_at, updated_at // FROM environments // WHERE workspace_id = ? // AND project_id = ? @@ -314,7 +314,7 @@ type Querier interface { //FindEnvironmentWithSettingsByProjectIdAndSlug // // SELECT - // e.pk, e.id, e.workspace_id, e.project_id, e.slug, e.description, e.sentinel_config, e.delete_protection, e.created_at, e.updated_at, + // e.pk, e.id, e.workspace_id, e.project_id, e.slug, e.description, e.delete_protection, e.created_at, e.updated_at, // ebs.pk, ebs.workspace_id, ebs.environment_id, ebs.dockerfile, ebs.docker_context, ebs.created_at, ebs.updated_at, // ers.pk, ers.workspace_id, ers.environment_id, ers.port, ers.cpu_millicores, ers.memory_mib, ers.command, ers.healthcheck, ers.region_config, ers.shutdown_signal, ers.sentinel_config, ers.created_at, ers.updated_at // FROM environments e @@ -1345,10 +1345,9 @@ type Querier interface { // slug, // description, // created_at, - // updated_at, - // sentinel_config + // updated_at // ) VALUES ( - // ?, ?, ?, ?, ?, ?, ?, ? + // ?, ?, ?, ?, ?, ?, ? // ) InsertEnvironment(ctx context.Context, db DBTX, arg InsertEnvironmentParams) error //InsertFrontlineRoute @@ -2109,7 +2108,7 @@ type Querier interface { ListPermissionsByRoleID(ctx context.Context, db DBTX, roleID string) ([]Permission, error) //ListPreviewEnvironments // - // SELECT pk, id, workspace_id, project_id, slug, description, sentinel_config, delete_protection, created_at, updated_at + // SELECT pk, id, workspace_id, project_id, slug, description, delete_protection, created_at, updated_at // FROM environments // WHERE slug = 'preview' // AND pk > ? @@ -2629,9 +2628,8 @@ type Querier interface { // workspace_id, // project_id, // slug, - // sentinel_config, // created_at - // ) VALUES (?, ?, ?, ?, ?, ?) + // ) VALUES (?, ?, ?, ?, ?) // ON DUPLICATE KEY UPDATE slug = VALUES(slug) UpsertEnvironment(ctx context.Context, db DBTX, arg UpsertEnvironmentParams) error //UpsertEnvironmentBuildSettings @@ -2661,9 +2659,10 @@ type Querier interface { // healthcheck, // region_config, // shutdown_signal, + // sentinel_config, // created_at, // updated_at - // ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + // ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) // ON DUPLICATE KEY UPDATE // port = VALUES(port), // cpu_millicores = VALUES(cpu_millicores), @@ -2672,6 +2671,7 @@ type Querier interface { // healthcheck = VALUES(healthcheck), // region_config = VALUES(region_config), // shutdown_signal = VALUES(shutdown_signal), + // sentinel_config = VALUES(sentinel_config), // updated_at = VALUES(updated_at) UpsertEnvironmentRuntimeSettings(ctx context.Context, db DBTX, arg UpsertEnvironmentRuntimeSettingsParams) error // Inserts a new identity or does nothing if one already exists for this workspace/external_id. diff --git a/pkg/db/queries/environment_insert.sql b/pkg/db/queries/environment_insert.sql index 39c4574fc5..7d2994ab84 100644 --- a/pkg/db/queries/environment_insert.sql +++ b/pkg/db/queries/environment_insert.sql @@ -6,8 +6,7 @@ INSERT INTO environments ( slug, description, created_at, - updated_at, - sentinel_config + updated_at ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ? ); diff --git a/pkg/db/queries/environment_runtime_settings_upsert.sql b/pkg/db/queries/environment_runtime_settings_upsert.sql index d8a4a8fa52..4b368b48b5 100644 --- a/pkg/db/queries/environment_runtime_settings_upsert.sql +++ b/pkg/db/queries/environment_runtime_settings_upsert.sql @@ -9,9 +9,10 @@ INSERT INTO environment_runtime_settings ( healthcheck, region_config, shutdown_signal, + sentinel_config, created_at, updated_at -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE port = VALUES(port), cpu_millicores = VALUES(cpu_millicores), @@ -20,4 +21,5 @@ ON DUPLICATE KEY UPDATE healthcheck = VALUES(healthcheck), region_config = VALUES(region_config), shutdown_signal = VALUES(shutdown_signal), + sentinel_config = VALUES(sentinel_config), updated_at = VALUES(updated_at); diff --git a/pkg/db/queries/environment_upsert.sql b/pkg/db/queries/environment_upsert.sql index d7e501dcfa..d784d68ca4 100644 --- a/pkg/db/queries/environment_upsert.sql +++ b/pkg/db/queries/environment_upsert.sql @@ -4,7 +4,6 @@ INSERT INTO environments ( workspace_id, project_id, slug, - sentinel_config, created_at -) VALUES (?, ?, ?, ?, ?, ?) +) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE slug = VALUES(slug); diff --git a/pkg/db/schema.sql b/pkg/db/schema.sql index 9531913cb3..33a7b0ab5f 100644 --- a/pkg/db/schema.sql +++ b/pkg/db/schema.sql @@ -354,7 +354,6 @@ CREATE TABLE `environments` ( `project_id` varchar(256) NOT NULL, `slug` varchar(256) NOT NULL, `description` varchar(255) NOT NULL DEFAULT '', - `sentinel_config` longblob NOT NULL, `delete_protection` boolean DEFAULT false, `created_at` bigint NOT NULL, `updated_at` bigint, @@ -403,7 +402,7 @@ CREATE TABLE `environment_runtime_settings` ( `healthcheck` json, `region_config` json NOT NULL DEFAULT ('{}'), `shutdown_signal` enum('SIGTERM','SIGINT','SIGQUIT','SIGKILL') NOT NULL DEFAULT 'SIGTERM', - `sentinel_config` longblob, + `sentinel_config` longblob NOT NULL, `created_at` bigint NOT NULL, `updated_at` bigint, CONSTRAINT `environment_runtime_settings_pk` PRIMARY KEY(`pk`), diff --git a/svc/api/internal/testutil/seed/seed.go b/svc/api/internal/testutil/seed/seed.go index 13836c6317..77573a69e1 100644 --- a/svc/api/internal/testutil/seed/seed.go +++ b/svc/api/internal/testutil/seed/seed.go @@ -192,22 +192,17 @@ type CreateEnvironmentRequest struct { // CreateEnvironment creates an environment within a project. If SentinelConfig is // nil or empty, it defaults to "{}". func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentRequest) db.Environment { - sentinelConfig := []byte("{}") - if len(req.SentinelConfig) > 0 { - sentinelConfig = req.SentinelConfig - } now := time.Now().UnixMilli() err := db.Query.InsertEnvironment(ctx, s.DB.RW(), db.InsertEnvironmentParams{ - ID: req.ID, - WorkspaceID: req.WorkspaceID, - ProjectID: req.ProjectID, - Slug: req.Slug, - Description: req.Description, - SentinelConfig: sentinelConfig, - CreatedAt: now, - UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, + ID: req.ID, + WorkspaceID: req.WorkspaceID, + ProjectID: req.ProjectID, + Slug: req.Slug, + Description: req.Description, + CreatedAt: now, + UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, }) require.NoError(s.t, err) @@ -220,6 +215,7 @@ func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentReq Command: dbtype.StringSlice{}, Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false}, RegionConfig: dbtype.RegionConfig{}, + SentinelConfig: []byte{}, ShutdownSignal: db.EnvironmentRuntimeSettingsShutdownSignalSIGTERM, CreatedAt: now, UpdatedAt: sql.NullInt64{Valid: true, Int64: now}, @@ -246,7 +242,6 @@ func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentReq ProjectID: environment.ProjectID, Slug: environment.Slug, Description: req.Description, - SentinelConfig: sentinelConfig, DeleteProtection: sql.NullBool{Valid: true, Bool: req.DeleteProtection}, CreatedAt: now, UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, diff --git a/svc/ctrl/api/github_webhook.go b/svc/ctrl/api/github_webhook.go index ef90613f32..10f2efdd2d 100644 --- a/svc/ctrl/api/github_webhook.go +++ b/svc/ctrl/api/github_webhook.go @@ -194,7 +194,7 @@ func (s *GitHubWebhook) handlePush(ctx context.Context, w http.ResponseWriter, b WorkspaceID: project.WorkspaceID, ProjectID: project.ID, EnvironmentID: env.ID, - SentinelConfig: []byte(envSettings.EnvironmentRuntimeSetting.SentinelConfig.String), + SentinelConfig: envSettings.EnvironmentRuntimeSetting.SentinelConfig, EncryptedEnvironmentVariables: secretsBlob, Command: envSettings.EnvironmentRuntimeSetting.Command, Status: db.DeploymentsStatusPending, diff --git a/svc/ctrl/integration/seed/seed.go b/svc/ctrl/integration/seed/seed.go index a378104d4b..42f8754392 100644 --- a/svc/ctrl/integration/seed/seed.go +++ b/svc/ctrl/integration/seed/seed.go @@ -174,22 +174,17 @@ type CreateEnvironmentRequest struct { } func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentRequest) db.Environment { - sentinelConfig := []byte("{}") - if len(req.SentinelConfig) > 0 { - sentinelConfig = req.SentinelConfig - } now := time.Now().UnixMilli() err := db.Query.InsertEnvironment(ctx, s.DB.RW(), db.InsertEnvironmentParams{ - ID: req.ID, - WorkspaceID: req.WorkspaceID, - ProjectID: req.ProjectID, - Slug: req.Slug, - Description: req.Description, - SentinelConfig: sentinelConfig, - CreatedAt: now, - UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, + ID: req.ID, + WorkspaceID: req.WorkspaceID, + ProjectID: req.ProjectID, + Slug: req.Slug, + Description: req.Description, + CreatedAt: now, + UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, }) require.NoError(s.t, err) @@ -202,6 +197,7 @@ func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentReq Command: dbtype.StringSlice{}, Healthcheck: dbtype.NullHealthcheck{Healthcheck: nil, Valid: false}, RegionConfig: dbtype.RegionConfig{}, + SentinelConfig: []byte{}, ShutdownSignal: db.EnvironmentRuntimeSettingsShutdownSignalSIGTERM, CreatedAt: now, UpdatedAt: sql.NullInt64{Valid: true, Int64: now}, @@ -228,7 +224,6 @@ func (s *Seeder) CreateEnvironment(ctx context.Context, req CreateEnvironmentReq ProjectID: environment.ProjectID, Slug: environment.Slug, Description: req.Description, - SentinelConfig: sentinelConfig, DeleteProtection: sql.NullBool{Valid: true, Bool: req.DeleteProtection}, CreatedAt: now, UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, diff --git a/svc/ctrl/services/deployment/create_deployment.go b/svc/ctrl/services/deployment/create_deployment.go index 287cf5b321..aa4cdc185f 100644 --- a/svc/ctrl/services/deployment/create_deployment.go +++ b/svc/ctrl/services/deployment/create_deployment.go @@ -158,7 +158,7 @@ func (s *Service) CreateDeployment( ProjectID: req.Msg.GetProjectId(), EnvironmentID: env.ID, OpenapiSpec: sql.NullString{String: "", Valid: false}, - SentinelConfig: []byte(envSettings.EnvironmentRuntimeSetting.SentinelConfig.String), + SentinelConfig: envSettings.EnvironmentRuntimeSetting.SentinelConfig, EncryptedEnvironmentVariables: secretsBlob, Command: envSettings.EnvironmentRuntimeSetting.Command, Status: db.DeploymentsStatusPending, diff --git a/web/apps/dashboard/lib/trpc/routers/deploy/project/create.ts b/web/apps/dashboard/lib/trpc/routers/deploy/project/create.ts index 141a3c7f0e..7bebb80bc0 100644 --- a/web/apps/dashboard/lib/trpc/routers/deploy/project/create.ts +++ b/web/apps/dashboard/lib/trpc/routers/deploy/project/create.ts @@ -93,7 +93,6 @@ export const createProject = workspaceProcedure projectId, slug: "production", description: "Production", - sentinelConfig: "", deleteProtection: false, createdAt: Date.now(), updatedAt: null, @@ -104,7 +103,6 @@ export const createProject = workspaceProcedure projectId, slug: "preview", description: "Preview", - sentinelConfig: "", deleteProtection: false, createdAt: Date.now(), updatedAt: null, @@ -124,10 +122,12 @@ export const createProject = workspaceProcedure { workspaceId: ctx.workspace.id, environmentId: prodEnvId, + sentinelConfig: "{}", }, { workspaceId: ctx.workspace.id, environmentId: previewEnvId, + sentinelConfig: "{}", }, ]); }); diff --git a/web/internal/db/src/schema/environment_runtime_settings.ts b/web/internal/db/src/schema/environment_runtime_settings.ts index 190c06fa9e..974d8f11f4 100644 --- a/web/internal/db/src/schema/environment_runtime_settings.ts +++ b/web/internal/db/src/schema/environment_runtime_settings.ts @@ -49,7 +49,7 @@ export const environmentRuntimeSettings = mysqlTable( .notNull() .default("SIGTERM"), - sentinelConfig: longblob("sentinel_config"), + sentinelConfig: longblob("sentinel_config").notNull(), ...lifecycleDates, }, diff --git a/web/internal/db/src/schema/environments.ts b/web/internal/db/src/schema/environments.ts index c942fe56c7..a01717a238 100644 --- a/web/internal/db/src/schema/environments.ts +++ b/web/internal/db/src/schema/environments.ts @@ -5,7 +5,6 @@ import { lifecycleDates } from "./util/lifecycle_dates"; import { workspaces } from "./workspaces"; import { projects } from "./projects"; -import { longblob } from "./util/longblob"; export const environments = mysqlTable( "environments", { @@ -18,10 +17,6 @@ export const environments = mysqlTable( slug: varchar("slug", { length: 256 }).notNull(), // URL-safe identifier within workspace description: varchar("description", { length: 255 }).notNull().default(""), - // @deprecated - // use environment_runtime_settings.sentinel_config instead - sentinelConfig: longblob("sentinel_config").notNull(), - ...deleteProtection, ...lifecycleDates, },