Altinn / altinn-profile

Altinn platform microservice for handling user profile
0 stars 1 forks source link

Establish KRR DB schema #186

Closed olebhansen closed 3 days ago

olebhansen commented 1 month ago

Description

Current plan is to copy the schema/structure from Altinn2. Use Entity Framework to import the schemas defined in Altinn 2. Posibly only 3 tables.

There should also be a column for user preferred language. I believe it's a new value Altinn 2 never added support for.

Acceptance criteria:

Recommendations for improvement

Ahmed-Ghanam commented 2 weeks ago

The database script:

-- Create the database
CREATE DATABASE profiledb
    WITH
    OWNER = postgres
    ENCODING = 'UTF8'
    LC_COLLATE = 'Norwegian_Norway.1252'
    LC_CTYPE = 'Norwegian_Norway.1252'
    LOCALE_PROVIDER = 'libc'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1
    IS_TEMPLATE = False;

-- Create schema if it doesn't exist
CREATE SCHEMA IF NOT EXISTS contact_and_reservation;

-- Grant access to the schema
GRANT ALL ON SCHEMA contact_and_reservation TO platform_profile_admin;
GRANT USAGE ON SCHEMA contact_and_reservation TO platform_profile;

-- Create table MailboxSupplier
CREATE TABLE IF NOT EXISTS contact_and_reservation.mailbox_supplier (
    mailbox_supplier_id INT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    org_number_ak CHAR(9) NOT NULL,
    CONSTRAINT unique_org_number_ak UNIQUE (org_number_ak)
);

-- Create table Metadata
CREATE TABLE IF NOT EXISTS contact_and_reservation.metadata (
    latest_change_number BIGINT PRIMARY KEY,
    exported TIMESTAMPTZ
);

-- Create table Person
CREATE TABLE IF NOT EXISTS contact_and_reservation.person (
    contact_and_reservation_user_id INT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
    fnumber_ak CHAR(11) NOT NULL UNIQUE,
    reservation BOOLEAN,
    description VARCHAR(20),
    mobile_phone_number VARCHAR(20),
    mobile_phone_number_last_updated TIMESTAMPTZ,
    mobile_phone_number_last_verified TIMESTAMPTZ,
    email_address VARCHAR(400),
    email_address_last_updated TIMESTAMPTZ,
    email_address_last_verified TIMESTAMPTZ,
    mailbox_address VARCHAR(50),
    mailbox_supplier_id_fk INT,
    x509_certificate TEXT,
    language_code CHAR(2) NULL,
    CONSTRAINT fk_mailbox_supplier FOREIGN KEY (mailbox_supplier_id_fk) REFERENCES contact_and_reservation.mailbox_supplier (mailbox_supplier_id),
    CONSTRAINT chk_language_code CHECK (language_code ~* '^[a-z]{2}$')
);

-- Indexes for performance
CREATE INDEX idx_fnumber_ak ON contact_and_reservation.person (fnumber_ak);
Ahmed-Ghanam commented 2 weeks ago

We follow the database-first approach. However, if we decide to go with a code-first approach, I can create the data models, configure the DbContext, write migrations, and use an in-memory database for testing.

SandGrainOne commented 2 weeks ago

I want a shorter schema name. I was thinking about simply "krr".

SandGrainOne commented 2 weeks ago

We can rename contact_and_reservation.register to contact_and_reservation.person. That is a better entity name for the table and makes it easier to create a logical name for the id: person_id

SandGrainOne commented 1 week ago

I've commented on most of the ideas you have @Ahmed-Ghanam

Ahmed-Ghanam commented 1 week ago

Til info @SandGrainOne:

SandGrainOne commented 1 week ago

We will use your schema name suggestion: contact_and_reservation. It's going to be a headache finding a schema name for "Offisiell varslingsinformasjon for virksomhet", but eh.

reservation is a bit hard to describe in a few words. People in Norway can use reservation to force the Norwegian goverment and agencies to use analog forms of communication with them. Like if you want to have your tax card on paper instead of digitally.

org_number_ak, organization number. There are a few suppliers of digital mail boxes and this column describes the organization number of those suppliers.

The latest_change_number and exported are used by the batch/synchronization job that reads from KRR. It's needed so that we keep track of were we are in the KRR change log. Maybe the solution is to rename the table? Instead of metadata. we could call it sync_data or something.

Ahmed-Ghanam commented 1 week ago

We will use your schema name suggestion: contact_and_reservation. It's going to be a headache finding a schema name for "Offisiell varslingsinformasjon for virksomhet", but eh.

reservation is a bit hard to describe in a few words. People in Norway can use reservation to force the Norwegian goverment and agencies to use analog forms of communication with them. Like if you want to have your tax card on paper instead of digitally.

org_number_ak, organization number. There are a few suppliers of digital mail boxes and this column describes the organization number of those suppliers.

The latest_change_number and exported are used by the batch/synchronization job that reads from KRR. It's needed so that we keep track of were we are in the KRR change log. Maybe the solution is to rename the table? Instead of metadata. we could call it sync_data or something.

I think we can go forward with these names as they are for now.