Add last tables structure

This commit is contained in:
Pierre HUBERT 2023-08-03 18:30:29 +02:00
parent 8cc720a214
commit 0abd0e5516
3 changed files with 93 additions and 8 deletions

View File

@ -1,5 +1,7 @@
-- This file should undo anything in `up.sql`
drop view if exists families_memberships ;
DROP view if EXISTS families_memberships ;
DROP table IF EXISTS couples;
DROP table IF EXISTS members;
DROP table IF EXISTS memberships ;
DROP table IF EXISTS families;
DROP table IF EXISTS users;

View File

@ -30,6 +30,46 @@ CREATE TABLE memberships (
PRIMARY KEY(user_id, family_id)
);
CREATE TABLE members (
id SERIAL PRIMARY KEY,
family_id integer NOT NULL REFERENCES families,
first_name VARCHAR(30) NULL,
last_name VARCHAR(30) NULL,
birth_last_name VARCHAR(30) NULL,
photo_id VARCHAR(255) NULL,
email VARCHAR(255) NULL,
phone VARCHAR(30) NULL,
address VARCHAR (155) NULL,
city VARCHAR(150) NULL,
postal_code VARCHAR(12) NULL,
country VARCHAR(30) NULL,
sex VARCHAR(1) NOT NULL,
time_create BIGINT NOT NULL,
time_update BIGINT NOT NULL,
mother integer NULL REFERENCES members,
father integer NULL REFERENCES members,
birth_year smallint NULL,
birth_month smallint NULL,
birth_day smallint NULL,
death_year smallint NULL,
death_month smallint NULL,
death_day smallint NULL,
note text NULL
);
CREATE TABLE couples (
wife integer NOT NULL REFERENCES members,
husband integer NOT NULL REFERENCES members,
wedding_year smallint NULL,
wedding_month smallint NULL,
wedding_day smallint NULL,
divorce_year smallint NULL,
divorce_month smallint NULL,
divorce_day smallint NULL,
PRIMARY KEY(wife, husband)
);
-- Create views
create view
families_memberships

View File

@ -1,16 +1,56 @@
// @generated automatically by Diesel CLI.
diesel::table! {
couples (wife, husband) {
wife -> Int4,
husband -> Int4,
wedding_year -> Nullable<Int2>,
wedding_month -> Nullable<Int2>,
wedding_day -> Nullable<Int2>,
divorce_year -> Nullable<Int2>,
divorce_month -> Nullable<Int2>,
divorce_day -> Nullable<Int2>,
}
}
diesel::table! {
families (id) {
id -> Int4,
time_create -> Int8,
#[max_length = 30]
name -> Varchar,
#[max_length = 7]
invitation_code -> Varchar,
}
}
diesel::table! {
members (id) {
id -> Int4,
family_id -> Int4,
first_name -> Nullable<Varchar>,
last_name -> Nullable<Varchar>,
birth_last_name -> Nullable<Varchar>,
photo_id -> Nullable<Varchar>,
email -> Nullable<Varchar>,
phone -> Nullable<Varchar>,
address -> Nullable<Varchar>,
city -> Nullable<Varchar>,
postal_code -> Nullable<Varchar>,
country -> Nullable<Varchar>,
sex -> Varchar,
time_create -> Int8,
time_update -> Int8,
mother -> Nullable<Int4>,
father -> Nullable<Int4>,
birth_year -> Nullable<Int2>,
birth_month -> Nullable<Int2>,
birth_day -> Nullable<Int2>,
death_year -> Nullable<Int2>,
death_month -> Nullable<Int2>,
death_day -> Nullable<Int2>,
note -> Nullable<Text>,
}
}
diesel::table! {
memberships (user_id, family_id) {
user_id -> Int4,
@ -23,16 +63,12 @@ diesel::table! {
diesel::table! {
users (id) {
id -> Int4,
#[max_length = 30]
name -> Varchar,
#[max_length = 255]
email -> Varchar,
password -> Nullable<Varchar>,
time_create -> Int8,
#[max_length = 150]
reset_password_token -> Nullable<Varchar>,
time_gen_reset_token -> Int8,
#[max_length = 150]
delete_account_token -> Nullable<Varchar>,
time_gen_delete_account_token -> Int8,
time_activate -> Int8,
@ -41,7 +77,14 @@ diesel::table! {
}
}
diesel::joinable!(members -> families (family_id));
diesel::joinable!(memberships -> families (family_id));
diesel::joinable!(memberships -> users (user_id));
diesel::allow_tables_to_appear_in_same_query!(families, memberships, users,);
diesel::allow_tables_to_appear_in_same_query!(
couples,
families,
members,
memberships,
users,
);