From cd70f54266d708867a1eb35870bc755bc5b2df32 Mon Sep 17 00:00:00 2001 From: ivar Date: Wed, 3 Dec 2025 21:49:20 +0100 Subject: Refactor db --- .../Migrations/20251026215643_Initial.Designer.cs | 214 -------------------- api/WhatApi/Migrations/20251026215643_Initial.cs | 143 -------------- .../20251202203059_PasswordMaxLength.Designer.cs | 215 --------------------- .../Migrations/20251202203059_PasswordMaxLength.cs | 36 ---- .../Migrations/20251203204812_Initial.Designer.cs | 215 +++++++++++++++++++++ api/WhatApi/Migrations/20251203204812_Initial.cs | 143 ++++++++++++++ api/WhatApi/Migrations/AppDatabaseModelSnapshot.cs | 212 ++++++++++++++++++++ api/WhatApi/Migrations/DatabaseModelSnapshot.cs | 212 -------------------- 8 files changed, 570 insertions(+), 820 deletions(-) delete mode 100644 api/WhatApi/Migrations/20251026215643_Initial.Designer.cs delete mode 100644 api/WhatApi/Migrations/20251026215643_Initial.cs delete mode 100644 api/WhatApi/Migrations/20251202203059_PasswordMaxLength.Designer.cs delete mode 100644 api/WhatApi/Migrations/20251202203059_PasswordMaxLength.cs create mode 100644 api/WhatApi/Migrations/20251203204812_Initial.Designer.cs create mode 100644 api/WhatApi/Migrations/20251203204812_Initial.cs create mode 100644 api/WhatApi/Migrations/AppDatabaseModelSnapshot.cs delete mode 100644 api/WhatApi/Migrations/DatabaseModelSnapshot.cs (limited to 'api/WhatApi/Migrations') diff --git a/api/WhatApi/Migrations/20251026215643_Initial.Designer.cs b/api/WhatApi/Migrations/20251026215643_Initial.Designer.cs deleted file mode 100644 index c430ed1..0000000 --- a/api/WhatApi/Migrations/20251026215643_Initial.Designer.cs +++ /dev/null @@ -1,214 +0,0 @@ -// -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 - { - /// - 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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection>("ChangedColumns") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("DateUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("EntityName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property>("NewValues") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property>("OldValues") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("PrimaryKey") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TrailType") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("EntityName"); - - b.ToTable("audit_trails", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Content", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("BlobId") - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Ip") - .IsRequired() - .HasColumnType("inet"); - - b.Property("Mime") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedBy") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("content", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Place", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ContentId") - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Location") - .IsRequired() - .HasColumnType("geometry(point,4326)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedBy") - .HasColumnType("uuid"); - - b.Property("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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("LastSeen") - .HasColumnType("timestamp with time zone"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("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 deleted file mode 100644 index b8f0444..0000000 --- a/api/WhatApi/Migrations/20251026215643_Initial.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.EntityFrameworkCore.Migrations; -using NetTopologySuite.Geometries; - -#nullable disable - -namespace WhatApi.Migrations -{ - /// - public partial class Initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterDatabase() - .Annotation("Npgsql:PostgresExtension:postgis", ",,"); - - migrationBuilder.CreateTable( - name: "audit_trails", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - UserId = table.Column(type: "uuid", nullable: true), - EntityName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - PrimaryKey = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), - TrailType = table.Column(type: "text", nullable: false), - DateUtc = table.Column(type: "timestamp with time zone", nullable: false), - OldValues = table.Column>(type: "jsonb", nullable: false), - NewValues = table.Column>(type: "jsonb", nullable: false), - ChangedColumns = table.Column>(type: "jsonb", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_audit_trails", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "content", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Mime = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - BlobId = table.Column(type: "uuid", nullable: false), - Ip = table.Column(type: "inet", nullable: false), - CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), - CreatedBy = table.Column(type: "uuid", nullable: false), - UpdatedBy = table.Column(type: "uuid", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_content", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "user", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), - Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), - Password = table.Column(type: "text", nullable: false), - LastSeen = table.Column(type: "timestamp with time zone", nullable: true), - CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), - CreatedBy = table.Column(type: "uuid", nullable: false), - UpdatedBy = table.Column(type: "uuid", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_user", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "place", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - ContentId = table.Column(type: "uuid", nullable: false), - Location = table.Column(type: "geometry(point,4326)", nullable: false), - CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), - CreatedBy = table.Column(type: "uuid", nullable: false), - UpdatedBy = table.Column(type: "uuid", nullable: true), - UserId = table.Column(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"); - } - - /// - 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/20251202203059_PasswordMaxLength.Designer.cs b/api/WhatApi/Migrations/20251202203059_PasswordMaxLength.Designer.cs deleted file mode 100644 index f23a067..0000000 --- a/api/WhatApi/Migrations/20251202203059_PasswordMaxLength.Designer.cs +++ /dev/null @@ -1,215 +0,0 @@ -// -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("20251202203059_PasswordMaxLength")] - partial class PasswordMaxLength - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("WhatApi.Tables.AuditTrail", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection("ChangedColumns") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("DateUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("EntityName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property>("NewValues") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property>("OldValues") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("PrimaryKey") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TrailType") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("EntityName"); - - b.ToTable("audit_trails", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Content", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("BlobId") - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Ip") - .IsRequired() - .HasColumnType("inet"); - - b.Property("Mime") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedBy") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("content", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Place", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ContentId") - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Location") - .IsRequired() - .HasColumnType("geometry(point,4326)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedBy") - .HasColumnType("uuid"); - - b.Property("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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("LastSeen") - .HasColumnType("timestamp with time zone"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("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/20251202203059_PasswordMaxLength.cs b/api/WhatApi/Migrations/20251202203059_PasswordMaxLength.cs deleted file mode 100644 index 8129df8..0000000 --- a/api/WhatApi/Migrations/20251202203059_PasswordMaxLength.cs +++ /dev/null @@ -1,36 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace WhatApi.Migrations -{ - /// - public partial class PasswordMaxLength : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Password", - table: "user", - type: "character varying(100)", - maxLength: 100, - nullable: false, - oldClrType: typeof(string), - oldType: "text"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterColumn( - name: "Password", - table: "user", - type: "text", - nullable: false, - oldClrType: typeof(string), - oldType: "character varying(100)", - oldMaxLength: 100); - } - } -} diff --git a/api/WhatApi/Migrations/20251203204812_Initial.Designer.cs b/api/WhatApi/Migrations/20251203204812_Initial.Designer.cs new file mode 100644 index 0000000..39847ba --- /dev/null +++ b/api/WhatApi/Migrations/20251203204812_Initial.Designer.cs @@ -0,0 +1,215 @@ +// +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.Database; + +#nullable disable + +namespace WhatApi.Migrations +{ + [DbContext(typeof(AppDatabase))] + [Migration("20251203204812_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("WhatApi.Database.Tables.AuditTrail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.PrimitiveCollection("ChangedColumns") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("DateUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("EntityName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property>("NewValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property>("OldValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("PrimaryKey") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("TrailType") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("EntityName"); + + b.ToTable("audit_trails", (string)null); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.Content", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BlobId") + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("inet"); + + b.Property("Mime") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("content", (string)null); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.Place", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ContentId") + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Location") + .IsRequired() + .HasColumnType("geometry(point,4326)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("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.Database.Tables.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("LastSeen") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.Place", b => + { + b.HasOne("WhatApi.Database.Tables.Content", "Content") + .WithMany() + .HasForeignKey("ContentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WhatApi.Database.Tables.User", null) + .WithMany("Places") + .HasForeignKey("UserId"); + + b.Navigation("Content"); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.User", b => + { + b.Navigation("Places"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/api/WhatApi/Migrations/20251203204812_Initial.cs b/api/WhatApi/Migrations/20251203204812_Initial.cs new file mode 100644 index 0000000..f49a9f3 --- /dev/null +++ b/api/WhatApi/Migrations/20251203204812_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 +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("Npgsql:PostgresExtension:postgis", ",,"); + + migrationBuilder.CreateTable( + name: "audit_trails", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserId = table.Column(type: "uuid", nullable: true), + EntityName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PrimaryKey = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), + TrailType = table.Column(type: "text", nullable: false), + DateUtc = table.Column(type: "timestamp with time zone", nullable: false), + OldValues = table.Column>(type: "jsonb", nullable: false), + NewValues = table.Column>(type: "jsonb", nullable: false), + ChangedColumns = table.Column(type: "jsonb", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_audit_trails", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "content", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Mime = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + BlobId = table.Column(type: "uuid", nullable: false), + Ip = table.Column(type: "inet", nullable: false), + CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), + CreatedBy = table.Column(type: "uuid", nullable: false), + UpdatedBy = table.Column(type: "uuid", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_content", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "user", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), + Email = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + PasswordHash = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), + LastSeen = table.Column(type: "timestamp with time zone", nullable: true), + CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), + CreatedBy = table.Column(type: "uuid", nullable: false), + UpdatedBy = table.Column(type: "uuid", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_user", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "place", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ContentId = table.Column(type: "uuid", nullable: false), + Location = table.Column(type: "geometry(point,4326)", nullable: false), + UserId = table.Column(type: "uuid", nullable: true), + CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), + CreatedBy = table.Column(type: "uuid", nullable: false), + UpdatedBy = table.Column(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"); + } + + /// + 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/AppDatabaseModelSnapshot.cs b/api/WhatApi/Migrations/AppDatabaseModelSnapshot.cs new file mode 100644 index 0000000..24973b0 --- /dev/null +++ b/api/WhatApi/Migrations/AppDatabaseModelSnapshot.cs @@ -0,0 +1,212 @@ +// +using System; +using System.Collections.Generic; +using System.Net; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using NetTopologySuite.Geometries; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using WhatApi.Database; + +#nullable disable + +namespace WhatApi.Migrations +{ + [DbContext(typeof(AppDatabase))] + partial class AppDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("WhatApi.Database.Tables.AuditTrail", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.PrimitiveCollection("ChangedColumns") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("DateUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("EntityName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property>("NewValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property>("OldValues") + .IsRequired() + .HasColumnType("jsonb"); + + b.Property("PrimaryKey") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("TrailType") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("EntityName"); + + b.ToTable("audit_trails", (string)null); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.Content", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("BlobId") + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Ip") + .IsRequired() + .HasColumnType("inet"); + + b.Property("Mime") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("content", (string)null); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.Place", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ContentId") + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Location") + .IsRequired() + .HasColumnType("geometry(point,4326)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.Property("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.Database.Tables.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .HasColumnType("uuid"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("LastSeen") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("PasswordHash") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedAtUtc") + .HasColumnType("timestamp with time zone"); + + b.Property("UpdatedBy") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("user", (string)null); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.Place", b => + { + b.HasOne("WhatApi.Database.Tables.Content", "Content") + .WithMany() + .HasForeignKey("ContentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("WhatApi.Database.Tables.User", null) + .WithMany("Places") + .HasForeignKey("UserId"); + + b.Navigation("Content"); + }); + + modelBuilder.Entity("WhatApi.Database.Tables.User", b => + { + b.Navigation("Places"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/api/WhatApi/Migrations/DatabaseModelSnapshot.cs b/api/WhatApi/Migrations/DatabaseModelSnapshot.cs deleted file mode 100644 index babdf01..0000000 --- a/api/WhatApi/Migrations/DatabaseModelSnapshot.cs +++ /dev/null @@ -1,212 +0,0 @@ -// -using System; -using System.Collections.Generic; -using System.Net; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using NetTopologySuite.Geometries; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using WhatApi; - -#nullable disable - -namespace WhatApi.Migrations -{ - [DbContext(typeof(Database))] - partial class DatabaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "10.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "postgis"); - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("WhatApi.Tables.AuditTrail", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.PrimitiveCollection("ChangedColumns") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("DateUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("EntityName") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property>("NewValues") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property>("OldValues") - .IsRequired() - .HasColumnType("jsonb"); - - b.Property("PrimaryKey") - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("TrailType") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("EntityName"); - - b.ToTable("audit_trails", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Content", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("BlobId") - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Ip") - .IsRequired() - .HasColumnType("inet"); - - b.Property("Mime") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedBy") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.ToTable("content", (string)null); - }); - - modelBuilder.Entity("WhatApi.Tables.Place", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("ContentId") - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Location") - .IsRequired() - .HasColumnType("geometry(point,4326)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("UpdatedBy") - .HasColumnType("uuid"); - - b.Property("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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("CreatedBy") - .HasColumnType("uuid"); - - b.Property("Email") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("LastSeen") - .HasColumnType("timestamp with time zone"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("character varying(50)"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(100) - .HasColumnType("character varying(100)"); - - b.Property("UpdatedAtUtc") - .HasColumnType("timestamp with time zone"); - - b.Property("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 - } - } -} -- cgit v1.3