Skip to content

Commit

Permalink
Create a new Migration folder and attach the database creation script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed-Ghanam committed Oct 8, 2024
1 parent 9a9a8b6 commit b14fe81
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Altinn.Profile.Integrations/Migration/profiledb.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Drop the database if it exists
DROP DATABASE IF EXISTS profiledb;

-- 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;

-- 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_mailbox_supplier_id_fk ON contact_and_reservation.person (mailbox_supplier_id_fk);
CREATE INDEX idx_fnumber_ak ON contact_and_reservation.person (fnumber_ak);

0 comments on commit b14fe81

Please sign in to comment.