Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: db party model #265

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@
"BaseArtifactsPath",
"ArtifactsPath",
"VersionFilePath"
],
"sqltools.format": {
"language": "sql",
"linesBetweenQueries": 2
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
var descriptor = builder.GetAltinnServiceDescriptor();
var yuniqlSchema = builder.Configuration.GetValue<string>($"Altinn:Npgsql:{descriptor.Name}:Yuniql:MigrationsTable:Schema");
var migrationsFs = new ManifestEmbeddedFileProvider(typeof(RegisterPersistenceExtensions).Assembly, "Migration");
////var seedDataFs = new ManifestEmbeddedFileProvider(typeof(RegisterPersistenceExtensions).Assembly, "TestData");
var seedDataFs = new ManifestEmbeddedFileProvider(typeof(RegisterPersistenceExtensions).Assembly, "TestData");
builder.AddAltinnPostgresDataSource()
////.SeedFromFileProvider(seedDataFs)
.SeedFromFileProvider(seedDataFs)
.AddYuniqlMigrations(y =>
{
y.WorkspaceFileProvider = migrationsFs;
Expand All @@ -60,5 +60,5 @@
});
}

private sealed record Marker;

Check warning on line 63 in src/Altinn.Register/src/Altinn.Register.Persistence/Microsoft.Extensions.Hosting/RegisterPersistenceExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze

Remove this empty record, write its code or make it an "interface". (https://rules.sonarsource.com/csharp/RSPEC-2094)

Check warning on line 63 in src/Altinn.Register/src/Altinn.Register.Persistence/Microsoft.Extensions.Hosting/RegisterPersistenceExtensions.cs

View workflow job for this annotation

GitHub Actions / Analyze

Remove this empty record, write its code or make it an "interface". (https://rules.sonarsource.com/csharp/RSPEC-2094)
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CREATE SCHEMA IF NOT EXISTS register;

Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
-- grant on tables
ALTER DEFAULT PRIVILEGES FOR USER "${YUNIQL-USER}" IN SCHEMA register
GRANT SELECT,
INSERT,
UPDATE,
REFERENCES,
DELETE,
TRUNCATE,
TRIGGER ON TABLES TO "${APP-USER}";
ALTER DEFAULT PRIVILEGES FOR USER "${YUNIQL-USER}" IN SCHEMA register GRANT
SELECT
, INSERT, UPDATE, REFERENCES, DELETE, TRUNCATE, TRIGGER ON TABLES TO "${APP-USER}";

-- grant on sequences
ALTER DEFAULT PRIVILEGES FOR USER "${YUNIQL-USER}" IN SCHEMA register
GRANT ALL ON SEQUENCES TO "${APP-USER}";
ALTER DEFAULT PRIVILEGES FOR USER "${YUNIQL-USER}" IN SCHEMA register GRANT ALL ON SEQUENCES TO "${APP-USER}";

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Enum: register.party_type
CREATE TYPE register.party_type AS ENUM(
'person',
'organization'
);

-- Enum: register.party_source
CREATE TYPE register.party_source AS ENUM(
Alxandr marked this conversation as resolved.
Show resolved Hide resolved
'folkeregistered',
'enhetsregisteret'
);

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Domain: register.person_identifier
CREATE DOMAIN register.person_identifier AS text CONSTRAINT fmtchk CHECK (value ~ '^[0-9]{11}$');

-- Domain: register.organization_identifier
CREATE DOMAIN register.organization_identifier AS text CONSTRAINT fmtchk CHECK (value ~ '^[0-9]{9}$');

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Composite: register._address (private - implementation detail)
CREATE TYPE register._address AS (
municipal_number text,
municipal_name text,
andreasisnes marked this conversation as resolved.
Show resolved Hide resolved
street_name text,
house_number text,
house_letter text,
apartment_number text,
postal_code text,
city text
);

-- Domain: register.address
-- No checks at this time, but create a domain so they can be added later
CREATE DOMAIN register.address AS register._address;

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Table: register.party
CREATE TABLE register.party(
uuid uuid PRIMARY KEY NOT NULL,
id bigint NOT NULL,
party_type register.party_type NOT NULL,
name text NOT NULL,
person_identifier register.person_identifier,
Alxandr marked this conversation as resolved.
Show resolved Hide resolved
organization_identifier register.organization_identifier,
created timestamp with time zone NOT NULL,
updated timestamp with time zone NOT NULL,
CONSTRAINT type_identifier_check CHECK ((party_type = 'person'::register.party_type AND person_identifier IS NOT NULL AND organization_identifier IS NULL) OR (party_type = 'organization'::register.party_type AND person_identifier IS NULL AND organization_identifier IS NOT NULL))
)
TABLESPACE pg_default;

CREATE UNIQUE INDEX uq_party_uuid ON register.party(uuid) INCLUDE (uuid, id, party_type, name, person_identifier, organization_identifier) TABLESPACE pg_default;

CREATE UNIQUE INDEX uq_party_id ON register.party(id) INCLUDE (uuid, id, party_type, name, person_identifier, organization_identifier) TABLESPACE pg_default;

CREATE UNIQUE INDEX uq_person_identifier ON register.party(person_identifier) INCLUDE (uuid, id, party_type, name, person_identifier, organization_identifier) TABLESPACE pg_default;

CREATE UNIQUE INDEX uq_organization_identifier ON register.party(organization_identifier) INCLUDE (uuid, id, party_type, name, person_identifier, organization_identifier) TABLESPACE pg_default;

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Table: register.party_source_ref
CREATE TABLE register.party_source_ref(
party_uuid uuid NOT NULL REFERENCES register.party(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
source register.party_source NOT NULL,
source_identifier text NOT NULL,
source_created timestamp with time zone,
source_updated timestamp with time zone,
PRIMARY KEY (party_uuid, source, source_identifier)
)
TABLESPACE pg_default;

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Table: register.person
CREATE TABLE register.person(
uuid uuid PRIMARY KEY NOT NULL REFERENCES register.party(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
first_name text NOT NULL,
middle_name text,
last_name text NOT NULL,
address register.address,
mailing_address register.address,
date_of_birth date,
date_of_death date
)
TABLESPACE pg_default;

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Table: register.organization
CREATE TABLE register.organization(
uuid uuid PRIMARY KEY NOT NULL REFERENCES register.party(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
unit_status text,
unit_type text,
telephone_number text,
mobile_number text,
fax_number text,
email_address text,
internet_address text,
mailing_address register.address,
business_address register.address
)
TABLESPACE pg_default;

Loading
Loading