Add new tables for families management

This commit is contained in:
Pierre HUBERT 2023-06-15 18:00:31 +02:00
parent 74601a8d9d
commit e6c896efa2
3 changed files with 48 additions and 3 deletions

View File

@ -1,2 +1,4 @@
-- This file should undo anything in `up.sql` -- This file should undo anything in `up.sql`
DROP table users; DROP table IF EXISTS memberships ;
DROP table IF EXISTS families;
DROP table IF EXISTS users;

View File

@ -1,4 +1,4 @@
-- Create table -- Create tables
CREATE TABLE users ( CREATE TABLE users (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
name VARCHAR(30) NOT NULL, name VARCHAR(30) NOT NULL,
@ -12,4 +12,20 @@ CREATE TABLE users (
time_activate BIGINT NOT NULL DEFAULT 0, time_activate BIGINT NOT NULL DEFAULT 0,
active BOOLEAN NOT NULL DEFAULT TRUE, active BOOLEAN NOT NULL DEFAULT TRUE,
admin BOOLEAN NOT NULL DEFAULT FALSE admin BOOLEAN NOT NULL DEFAULT FALSE
) );
CREATE TABLE families(
id SERIAL PRIMARY KEY,
time_create BIGINT NOT NULL,
name VARCHAR(30) NOT NULL,
invitation_code VARCHAR(7) NOT NULL
);
CREATE TABLE memberships(
user_id integer NOT NULL REFERENCES users,
family_id integer NOT NULL REFERENCES families,
time_create BIGINT NOT NULL,
is_admin BOOLEAN NOT NULL DEFAULT TRUE,
PRIMARY KEY(user_id, family_id)
);

View File

@ -1,5 +1,23 @@
// @generated automatically by Diesel CLI. // @generated automatically by Diesel CLI.
diesel::table! {
families (id) {
id -> Int4,
time_create -> Int8,
name -> Varchar,
invitation_code -> Varchar,
}
}
diesel::table! {
memberships (user_id, family_id) {
user_id -> Int4,
family_id -> Int4,
time_create -> Int8,
is_admin -> Bool,
}
}
diesel::table! { diesel::table! {
users (id) { users (id) {
id -> Int4, id -> Int4,
@ -16,3 +34,12 @@ diesel::table! {
admin -> Bool, admin -> Bool,
} }
} }
diesel::joinable!(memberships -> families (family_id));
diesel::joinable!(memberships -> users (user_id));
diesel::allow_tables_to_appear_in_same_query!(
families,
memberships,
users,
);