diff --git a/geneit_backend/migrations/2023-05-24-102711_create_users/down.sql b/geneit_backend/migrations/2023-05-24-102711_create_users/down.sql index f1c3bfb..10bdd70 100644 --- a/geneit_backend/migrations/2023-05-24-102711_create_users/down.sql +++ b/geneit_backend/migrations/2023-05-24-102711_create_users/down.sql @@ -1,2 +1,4 @@ -- This file should undo anything in `up.sql` -DROP table users; \ No newline at end of file +DROP table IF EXISTS memberships ; +DROP table IF EXISTS families; +DROP table IF EXISTS users; \ No newline at end of file diff --git a/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql b/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql index 1dfe1c9..fd1c0a2 100644 --- a/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql +++ b/geneit_backend/migrations/2023-05-24-102711_create_users/up.sql @@ -1,4 +1,4 @@ --- Create table +-- Create tables CREATE TABLE users ( id SERIAL PRIMARY KEY, name VARCHAR(30) NOT NULL, @@ -12,4 +12,20 @@ CREATE TABLE users ( time_activate BIGINT NOT NULL DEFAULT 0, active BOOLEAN NOT NULL DEFAULT TRUE, admin BOOLEAN NOT NULL DEFAULT FALSE -) \ No newline at end of file +); + +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) +); \ No newline at end of file diff --git a/geneit_backend/src/schema.rs b/geneit_backend/src/schema.rs index 589622d..a9b1103 100644 --- a/geneit_backend/src/schema.rs +++ b/geneit_backend/src/schema.rs @@ -1,5 +1,23 @@ // @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! { users (id) { id -> Int4, @@ -16,3 +34,12 @@ diesel::table! { 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, +);