diff options
| author | ivar <i@oiee.no> | 2025-10-26 22:57:28 +0100 |
|---|---|---|
| committer | ivar <i@oiee.no> | 2025-10-26 22:57:28 +0100 |
| commit | 842502e82c4ddfea05a5f77c361aaa27f75afc42 (patch) | |
| tree | 70fe96cd88600224257b80569015008626e3d317 /api/WhatApi/Migrations | |
| parent | 5c59225ee10949cc58fccce4d968d1ede58be9b6 (diff) | |
| download | what-842502e82c4ddfea05a5f77c361aaa27f75afc42.tar.xz what-842502e82c4ddfea05a5f77c361aaa27f75afc42.zip | |
Refactor db schema and add audits
Diffstat (limited to 'api/WhatApi/Migrations')
| -rw-r--r-- | api/WhatApi/Migrations/20251013213511_Initial.Designer.cs | 93 | ||||
| -rw-r--r-- | api/WhatApi/Migrations/20251013213511_Initial.cs | 75 | ||||
| -rw-r--r-- | api/WhatApi/Migrations/20251026215643_Initial.Designer.cs | 214 | ||||
| -rw-r--r-- | api/WhatApi/Migrations/20251026215643_Initial.cs | 143 | ||||
| -rw-r--r-- | api/WhatApi/Migrations/DatabaseModelSnapshot.cs | 129 |
5 files changed, 482 insertions, 172 deletions
diff --git a/api/WhatApi/Migrations/20251013213511_Initial.Designer.cs b/api/WhatApi/Migrations/20251013213511_Initial.Designer.cs deleted file mode 100644 index 5ddcc9f..0000000 --- a/api/WhatApi/Migrations/20251013213511_Initial.Designer.cs +++ /dev/null @@ -1,93 +0,0 @@ -// <auto-generated /> -using System; -using System.Net; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using NetTopologySuite.Geometries; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using WhatApi; - -#nullable disable - -namespace WhatApi.Migrations -{ - [DbContext(typeof(Database))] - [Migration("20251013213511_Initial")] - partial class Initial - { - /// <inheritdoc /> - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.9") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("WhatApi.Tables.Content", b => - { - b.Property<Guid>("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property<Guid>("BlobId") - .HasColumnType("uuid"); - - b.Property<DateTime>("Created") - .HasColumnType("timestamp with time zone"); - - b.Property<IPAddress>("Ip") - .IsRequired() - .HasColumnType("inet"); - - b.Property<string>("Mime") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Content"); - }); - - modelBuilder.Entity("WhatApi.Tables.Place", b => - { - b.Property<Guid>("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property<Guid>("ContentId") - .HasColumnType("uuid"); - - b.Property<Point>("Location") - .IsRequired() - .HasColumnType("geometry(point,4326)"); - - b.HasKey("Id"); - - b.HasIndex("ContentId"); - - b.HasIndex("Location"); - - NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Location"), "gist"); - - b.ToTable("Place", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Place", b => - { - b.HasOne("WhatApi.Tables.Content", "Content") - .WithMany() - .HasForeignKey("ContentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Content"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/api/WhatApi/Migrations/20251013213511_Initial.cs b/api/WhatApi/Migrations/20251013213511_Initial.cs deleted file mode 100644 index 1fa8bbf..0000000 --- a/api/WhatApi/Migrations/20251013213511_Initial.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Net; -using Microsoft.EntityFrameworkCore.Migrations; -using NetTopologySuite.Geometries; - -#nullable disable - -namespace WhatApi.Migrations -{ - /// <inheritdoc /> - public partial class Initial : Migration - { - /// <inheritdoc /> - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterDatabase() - .Annotation("Npgsql:PostgresExtension:postgis", ",,"); - - migrationBuilder.CreateTable( - name: "Content", - columns: table => new - { - Id = table.Column<Guid>(type: "uuid", nullable: false), - Mime = table.Column<string>(type: "text", nullable: false), - Created = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), - BlobId = table.Column<Guid>(type: "uuid", nullable: false), - Ip = table.Column<IPAddress>(type: "inet", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Content", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Place", - columns: table => new - { - Id = table.Column<Guid>(type: "uuid", nullable: false), - ContentId = table.Column<Guid>(type: "uuid", nullable: false), - Location = table.Column<Point>(type: "geometry(point,4326)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Place", x => x.Id); - table.ForeignKey( - name: "FK_Place_Content_ContentId", - column: x => x.ContentId, - principalTable: "Content", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Place_ContentId", - table: "Place", - column: "ContentId"); - - migrationBuilder.CreateIndex( - name: "IX_Place_Location", - table: "Place", - column: "Location") - .Annotation("Npgsql:IndexMethod", "gist"); - } - - /// <inheritdoc /> - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Place"); - - migrationBuilder.DropTable( - name: "Content"); - } - } -} diff --git a/api/WhatApi/Migrations/20251026215643_Initial.Designer.cs b/api/WhatApi/Migrations/20251026215643_Initial.Designer.cs new file mode 100644 index 0000000..c430ed1 --- /dev/null +++ b/api/WhatApi/Migrations/20251026215643_Initial.Designer.cs @@ -0,0 +1,214 @@ +// <auto-generated /> +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using NetTopologySuite.Geometries; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using WhatApi; + +#nullable disable + +namespace WhatApi.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20251026215643_Initial")] + partial class Initial + { + /// <inheritdoc /> + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("WhatApi.Tables.AuditTrail", b => + { + b.Property<Guid>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.PrimitiveCollection<List<string>>("ChangedColumns") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property<DateTimeOffset>("DateUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<string>("EntityName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<Dictionary<string, object>>("NewValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property<Dictionary<string, object>>("OldValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property<string>("PrimaryKey") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<string>("TrailType") + .IsRequired() + .HasColumnType("text"); + + b.Property<Guid?>("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("EntityName"); + + b.ToTable("audit_trails", (string)null); + }); + + modelBuilder.Entity("WhatApi.Tables.Content", b => + { + b.Property<Guid>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property<Guid>("BlobId") + .HasColumnType("uuid"); + + b.Property<DateTimeOffset>("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid>("CreatedBy") + .HasColumnType("uuid"); + + b.Property<IPAddress>("Ip") + .IsRequired() + .HasColumnType("inet"); + + b.Property<string>("Mime") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<DateTimeOffset?>("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid?>("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("content", (string)null); + }); + + modelBuilder.Entity("WhatApi.Tables.Place", b => + { + b.Property<Guid>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property<Guid>("ContentId") + .HasColumnType("uuid"); + + b.Property<DateTimeOffset>("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid>("CreatedBy") + .HasColumnType("uuid"); + + b.Property<Point>("Location") + .IsRequired() + .HasColumnType("geometry(point,4326)"); + + b.Property<DateTimeOffset?>("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid?>("UpdatedBy") + .HasColumnType("uuid"); + + b.Property<Guid?>("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ContentId"); + + b.HasIndex("Location"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Location"), "gist"); + + b.HasIndex("UserId"); + + b.ToTable("place", (string)null); + }); + + modelBuilder.Entity("WhatApi.Tables.User", b => + { + b.Property<Guid>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property<DateTimeOffset>("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid>("CreatedBy") + .HasColumnType("uuid"); + + b.Property<string>("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<DateTimeOffset?>("LastSeen") + .HasColumnType("timestamp with time zone"); + + b.Property<string>("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property<string>("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property<DateTimeOffset?>("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid?>("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("WhatApi.Tables.Place", b => + { + b.HasOne("WhatApi.Tables.Content", "Content") + .WithMany() + .HasForeignKey("ContentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WhatApi.Tables.User", null) + .WithMany("Places") + .HasForeignKey("UserId"); + + b.Navigation("Content"); + }); + + modelBuilder.Entity("WhatApi.Tables.User", b => + { + b.Navigation("Places"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/api/WhatApi/Migrations/20251026215643_Initial.cs b/api/WhatApi/Migrations/20251026215643_Initial.cs new file mode 100644 index 0000000..b8f0444 --- /dev/null +++ b/api/WhatApi/Migrations/20251026215643_Initial.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.EntityFrameworkCore.Migrations; +using NetTopologySuite.Geometries; + +#nullable disable + +namespace WhatApi.Migrations +{ + /// <inheritdoc /> + public partial class Initial : Migration + { + /// <inheritdoc /> + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("Npgsql:PostgresExtension:postgis", ",,"); + + migrationBuilder.CreateTable( + name: "audit_trails", + columns: table => new + { + Id = table.Column<Guid>(type: "uuid", nullable: false), + UserId = table.Column<Guid>(type: "uuid", nullable: true), + EntityName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false), + PrimaryKey = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true), + TrailType = table.Column<string>(type: "text", nullable: false), + DateUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false), + OldValues = table.Column<Dictionary<string, object>>(type: "jsonb", nullable: false), + NewValues = table.Column<Dictionary<string, object>>(type: "jsonb", nullable: false), + ChangedColumns = table.Column<List<string>>(type: "jsonb", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_audit_trails", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "content", + columns: table => new + { + Id = table.Column<Guid>(type: "uuid", nullable: false), + Mime = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false), + BlobId = table.Column<Guid>(type: "uuid", nullable: false), + Ip = table.Column<IPAddress>(type: "inet", nullable: false), + CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false), + UpdatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true), + CreatedBy = table.Column<Guid>(type: "uuid", nullable: false), + UpdatedBy = table.Column<Guid>(type: "uuid", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_content", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column<Guid>(type: "uuid", nullable: false), + Name = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false), + Password = table.Column<string>(type: "text", nullable: false), + LastSeen = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true), + CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false), + UpdatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true), + CreatedBy = table.Column<Guid>(type: "uuid", nullable: false), + UpdatedBy = table.Column<Guid>(type: "uuid", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "place", + columns: table => new + { + Id = table.Column<Guid>(type: "uuid", nullable: false), + ContentId = table.Column<Guid>(type: "uuid", nullable: false), + Location = table.Column<Point>(type: "geometry(point,4326)", nullable: false), + CreatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false), + UpdatedAtUtc = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true), + CreatedBy = table.Column<Guid>(type: "uuid", nullable: false), + UpdatedBy = table.Column<Guid>(type: "uuid", nullable: true), + UserId = table.Column<Guid>(type: "uuid", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_place", x => x.Id); + table.ForeignKey( + name: "FK_place_content_ContentId", + column: x => x.ContentId, + principalTable: "content", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_place_user_UserId", + column: x => x.UserId, + principalTable: "user", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_audit_trails_EntityName", + table: "audit_trails", + column: "EntityName"); + + migrationBuilder.CreateIndex( + name: "IX_place_ContentId", + table: "place", + column: "ContentId"); + + migrationBuilder.CreateIndex( + name: "IX_place_Location", + table: "place", + column: "Location") + .Annotation("Npgsql:IndexMethod", "gist"); + + migrationBuilder.CreateIndex( + name: "IX_place_UserId", + table: "place", + column: "UserId"); + } + + /// <inheritdoc /> + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "audit_trails"); + + migrationBuilder.DropTable( + name: "place"); + + migrationBuilder.DropTable( + name: "content"); + + migrationBuilder.DropTable( + name: "user"); + } + } +} diff --git a/api/WhatApi/Migrations/DatabaseModelSnapshot.cs b/api/WhatApi/Migrations/DatabaseModelSnapshot.cs index f1e5fcb..1d81e04 100644 --- a/api/WhatApi/Migrations/DatabaseModelSnapshot.cs +++ b/api/WhatApi/Migrations/DatabaseModelSnapshot.cs @@ -1,5 +1,6 @@ // <auto-generated /> using System; +using System.Collections.Generic; using System.Net; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; @@ -25,6 +26,50 @@ namespace WhatApi.Migrations NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("WhatApi.Tables.AuditTrail", b => + { + b.Property<Guid>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.PrimitiveCollection<List<string>>("ChangedColumns") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property<DateTimeOffset>("DateUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<string>("EntityName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<Dictionary<string, object>>("NewValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property<Dictionary<string, object>>("OldValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property<string>("PrimaryKey") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<string>("TrailType") + .IsRequired() + .HasColumnType("text"); + + b.Property<Guid?>("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("EntityName"); + + b.ToTable("audit_trails", (string)null); + }); + modelBuilder.Entity("WhatApi.Tables.Content", b => { b.Property<Guid>("Id") @@ -34,20 +79,30 @@ namespace WhatApi.Migrations b.Property<Guid>("BlobId") .HasColumnType("uuid"); - b.Property<DateTime>("Created") + b.Property<DateTimeOffset>("CreatedAtUtc") .HasColumnType("timestamp with time zone"); + b.Property<Guid>("CreatedBy") + .HasColumnType("uuid"); + b.Property<IPAddress>("Ip") .IsRequired() .HasColumnType("inet"); b.Property<string>("Mime") .IsRequired() - .HasColumnType("text"); + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<DateTimeOffset?>("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid?>("UpdatedBy") + .HasColumnType("uuid"); b.HasKey("Id"); - b.ToTable("Content"); + b.ToTable("content", (string)null); }); modelBuilder.Entity("WhatApi.Tables.Place", b => @@ -59,10 +114,25 @@ namespace WhatApi.Migrations b.Property<Guid>("ContentId") .HasColumnType("uuid"); + b.Property<DateTimeOffset>("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid>("CreatedBy") + .HasColumnType("uuid"); + b.Property<Point>("Location") .IsRequired() .HasColumnType("geometry(point,4326)"); + b.Property<DateTimeOffset?>("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid?>("UpdatedBy") + .HasColumnType("uuid"); + + b.Property<Guid?>("UserId") + .HasColumnType("uuid"); + b.HasKey("Id"); b.HasIndex("ContentId"); @@ -71,7 +141,49 @@ namespace WhatApi.Migrations NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("Location"), "gist"); - b.ToTable("Place", (string)null); + b.HasIndex("UserId"); + + b.ToTable("place", (string)null); + }); + + modelBuilder.Entity("WhatApi.Tables.User", b => + { + b.Property<Guid>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property<DateTimeOffset>("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid>("CreatedBy") + .HasColumnType("uuid"); + + b.Property<string>("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property<DateTimeOffset?>("LastSeen") + .HasColumnType("timestamp with time zone"); + + b.Property<string>("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property<string>("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property<DateTimeOffset?>("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property<Guid?>("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("user", (string)null); }); modelBuilder.Entity("WhatApi.Tables.Place", b => @@ -82,8 +194,17 @@ namespace WhatApi.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("WhatApi.Tables.User", null) + .WithMany("Places") + .HasForeignKey("UserId"); + b.Navigation("Content"); }); + + modelBuilder.Entity("WhatApi.Tables.User", b => + { + b.Navigation("Places"); + }); #pragma warning restore 612, 618 } } |
