Skip to content

Commit

Permalink
feat: normalize deployments table (#14366)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkoSekulic authored Jan 10, 2025
1 parent 683992b commit 04104da
Show file tree
Hide file tree
Showing 49 changed files with 1,283 additions and 584 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The development environment consist of several services defined in [compose.yaml
- `studio-repos` which is [gitea][14] with some custom config. More [here](gitea/README.md).
- `studio-db` which is a postgres database used by both `studio-designer` and `studio-repos`.
- `database_migrations` which is a one-time task container designed to perform and complete database migrations before exiting.
- `pgadmin` which is a administration and development platform for PostgreSQL.
- `redis` which is a redis cache used by designer.
- `redis-commander` which is a ui for redis cache.

Expand Down
2 changes: 1 addition & 1 deletion backend/Migrations.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV OidcLoginSettings__FetchClientIdAndSecretFromRootEnvFile=false
ENV OidcLoginSettings__ClientId=dummyRequired
ENV OidcLoginSettings__ClientSecret=dummyRequired

RUN dotnet ef migrations script --project src/Designer/Designer.csproj -o /app/migrations.sql
RUN dotnet ef migrations script --project src/Designer/Designer.csproj --idempotent -o /app/migrations.sql

FROM alpine:3.21.0 AS final
COPY --from=build /app/migrations.sql migrations.sql
Expand Down
4 changes: 2 additions & 2 deletions backend/src/Designer/Infrastructure/ServiceRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static IServiceCollection RegisterServiceImplementations(this IServiceCol
options.UseNpgsql(postgresSettings.FormattedConnectionString());
});

services.AddScoped<IReleaseRepository, ORMReleaseRepository>();
services.AddScoped<IDeploymentRepository, ORMDeploymentRepository>();
services.AddScoped<IReleaseRepository, ReleaseRepository>();
services.AddScoped<IDeploymentRepository, DeploymentRepository>();
services.AddScoped<IAppScopesRepository, AppScopesRepository>();
services.AddTransient<IReleaseService, ReleaseService>();
services.AddTransient<IDeploymentService, DeploymentService>();
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace Altinn.Studio.Designer.Migrations
{
/// <inheritdoc />
public partial class AddBuidsTableAndDeploymentsColumns : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "created_by",
schema: "designer",
table: "deployments",
type: "character varying",
nullable: true);

migrationBuilder.AddColumn<string>(
name: "envname",
schema: "designer",
table: "deployments",
type: "character varying",
nullable: true);

migrationBuilder.AddColumn<long>(
name: "internal_build_id",
schema: "designer",
table: "deployments",
type: "bigint",
nullable: true);

migrationBuilder.CreateTable(
name: "builds",
schema: "designer",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
external_id = table.Column<string>(type: "character varying", nullable: true),
status = table.Column<string>(type: "character varying", nullable: true),
result = table.Column<string>(type: "character varying", nullable: true),
build_type = table.Column<int>(type: "integer", nullable: false),
started = table.Column<DateTimeOffset>(type: "timestamptz", nullable: true),
finished = table.Column<DateTimeOffset>(type: "timestamptz", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_builds", x => x.id);
});

migrationBuilder.CreateIndex(
name: "IX_deployments_internal_build_id",
schema: "designer",
table: "deployments",
column: "internal_build_id");

migrationBuilder.CreateIndex(
name: "IX_builds_build_type",
schema: "designer",
table: "builds",
column: "build_type");

migrationBuilder.CreateIndex(
name: "IX_builds_external_id_build_type",
schema: "designer",
table: "builds",
columns: new[] { "external_id", "build_type" },
unique: true);

migrationBuilder.AddForeignKey(
name: "fk_deployments_builds_buildid",
schema: "designer",
table: "deployments",
column: "internal_build_id",
principalSchema: "designer",
principalTable: "builds",
principalColumn: "id");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_deployments_builds_buildid",
schema: "designer",
table: "deployments");

migrationBuilder.DropTable(
name: "builds",
schema: "designer");

migrationBuilder.DropIndex(
name: "IX_deployments_internal_build_id",
schema: "designer",
table: "deployments");

migrationBuilder.DropColumn(
name: "created_by",
schema: "designer",
table: "deployments");

migrationBuilder.DropColumn(
name: "envname",
schema: "designer",
table: "deployments");

migrationBuilder.DropColumn(
name: "internal_build_id",
schema: "designer",
table: "deployments");
}
}
}
Loading

0 comments on commit 04104da

Please sign in to comment.