[#46] MemberHistory: Add Type to PK

This commit is contained in:
2024-06-17 01:19:25 +02:00
parent b76c5ea874
commit 9d9f929843
4 changed files with 22 additions and 6 deletions

View File

@ -9,7 +9,7 @@ namespace Elwig.Helpers {
public static class AppDbUpdater {
// Don't forget to update value in Tests/fetch-resources.bat!
public static readonly int RequiredSchemaVersion = 20;
public static readonly int RequiredSchemaVersion = 21;
private static int VersionOffset = 0;

View File

@ -3,7 +3,7 @@ using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models.Entities {
[Table("member_history"), PrimaryKey("MgNr", "DateString")]
[Table("member_history"), PrimaryKey("MgNr", "DateString", "Type")]
public class MemberHistory {
[Column("mgnr")]
public int MgNr { get; set; }
@ -16,12 +16,12 @@ namespace Elwig.Models.Entities {
set => value.ToString("yyyy-MM-dd");
}
[Column("business_shares")]
public int BusinessShares { get; set; }
[Column("type")]
public required string Type { get; set; }
[Column("business_shares")]
public int BusinessShares { get; set; }
[Column("comment")]
public string? Comment { get; set; }

View File

@ -0,0 +1,16 @@
-- schema version 20 to 21
DROP TABLE member_history;
CREATE TABLE member_history (
mgnr INTEGER NOT NULL,
date TEXT NOT NULL CHECK (date REGEXP '^[1-9][0-9]{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$') DEFAULT CURRENT_DATE,
type TEXT NOT NULL CHECK (type REGEXP '^[a-z_]+$'),
business_shares INTEGER NOT NULL,
comment TEXT DEFAULT NULL,
CONSTRAINT pk_member_history PRIMARY KEY (mgnr, date, type),
CONSTRAINT fk_member_history_member FOREIGN KEY (mgnr) REFERENCES member (mgnr)
ON UPDATE CASCADE
ON DELETE CASCADE
) STRICT;

View File

@ -1 +1 @@
curl --fail -s -L "https://elwig.at/files/create.sql?v=20" -u "elwig:ganzGeheim123!" -o "Resources\Sql\Create.sql"
curl --fail -s -L "https://elwig.at/files/create.sql?v=21" -u "elwig:ganzGeheim123!" -o "Resources\Sql\Create.sql"