-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge the feature branch that includes the Database schema file
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |