Initial commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
-- drop database if exists settlementsint
|
||||
-- create database settlements;
|
||||
|
||||
create table users (
|
||||
id integer primary key autoincrement,
|
||||
name varchar,
|
||||
surnames varchar,
|
||||
email varchar
|
||||
);
|
||||
|
||||
create table user_accounts (
|
||||
id integer primary key autoincrement,
|
||||
user_id bigint references users (id) unique,
|
||||
username varchar unique not null,
|
||||
password varchar default null,
|
||||
attempts smallint default 0,
|
||||
locked bool default false,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table permissions (
|
||||
id integer primary key autoincrement,
|
||||
code varchar unique not null,
|
||||
description varchar default null
|
||||
);
|
||||
|
||||
create table groups (
|
||||
id integer primary key autoincrement,
|
||||
code varchar unique not null,
|
||||
description varchar default null
|
||||
);
|
||||
|
||||
create table user_account_groups (
|
||||
account_id bigint references user_accounts (id),
|
||||
group_id bigint references groups (id)
|
||||
);
|
||||
|
||||
create table user_account_permissions (
|
||||
account_id bigint references user_accounts (id),
|
||||
permission_id bigint references permissions (id)
|
||||
);
|
||||
|
||||
create table group_permissions (
|
||||
group_id bigint references groups (id),
|
||||
permission_id bigint references permissions (id)
|
||||
);
|
||||
|
||||
create table user_account_sessions (
|
||||
id integer primary key autoincrement,
|
||||
account_id bigint not null references user_accounts (id),
|
||||
token varchar not null unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table user_account_recover_requests (
|
||||
id integer primary key autoincrement,
|
||||
account_id bigint not null references user_accounts (id),
|
||||
token varchar not null unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table settlements (
|
||||
id integer primary key autoincrement,
|
||||
name varchar not null unique,
|
||||
address varchar not null unique,
|
||||
created_at timestamp not null default current_timestamp,
|
||||
last_done timestamp default null,
|
||||
last_done_by bigint references users (id),
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_coats (
|
||||
id integer primary key autoincrement,
|
||||
code varchar unique not null,
|
||||
description varchar default null
|
||||
);
|
||||
|
||||
create table animals (
|
||||
id integer primary key autoincrement,
|
||||
name varchar not null,
|
||||
microchip varchar default null,
|
||||
coat bigint not null references animal_coats (id),
|
||||
sex int not null check(sex in ('female', 'male', 'unknown')) default 'unknown',
|
||||
settlement_id bigint references settlements (id),
|
||||
has_ear_mark bool default false,
|
||||
controlled bool default false,
|
||||
castrated bool default false,
|
||||
adopted bool default false,
|
||||
friendly bool default null,
|
||||
friendly_children bool default null,
|
||||
friendly_dogs bool default null,
|
||||
first_view timestamp default null,
|
||||
last_view timestamp default null,
|
||||
created_at timestamp not null default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_comments (
|
||||
id integer primary key autoincrement,
|
||||
animal_id bigint not null references animals (id),
|
||||
_type int not null check(_type in ('info', 'alert')) default 'info',
|
||||
message varchar not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
public bool default false,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_alerts (
|
||||
id integer primary key autoincrement,
|
||||
animal_id bigint not null references animals (id),
|
||||
_type int not null check(_type in ('info', 'low', 'medium', 'high', 'ultra')) default 'high',
|
||||
comment varchar not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_images (
|
||||
id integer primary key autoincrement,
|
||||
animal_id bigint not null references animals (id),
|
||||
image varchar not null unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
is_primary bool default false,
|
||||
public bool default false,
|
||||
active bool default true
|
||||
);
|
||||
@@ -0,0 +1,82 @@
|
||||
insert into
|
||||
animal_coats (code)
|
||||
values
|
||||
('NEGRO'),
|
||||
('NARANJA'),
|
||||
('BLANCO'),
|
||||
('CHOCOLATE');
|
||||
|
||||
insert into
|
||||
animal_coats (code, description)
|
||||
values
|
||||
('CAREY', 'Mezcla irregular de negro y rojo'),
|
||||
('AZUL', 'Gris diluido'),
|
||||
('CANELA', 'Marrón claro con toque dorado'),
|
||||
('LILA', 'Crema con tono lavanda'),
|
||||
('CREMA', 'Naranja pálido'),
|
||||
('CALICO', 'Combina blanco, negro y naranja'),
|
||||
('ATIGRADO', 'Con rayas o espirales definidas'),
|
||||
(
|
||||
'COLORPOINT',
|
||||
'Cuerpo claro con extremidades oscuras'
|
||||
),
|
||||
(
|
||||
'AHUMADO',
|
||||
'Pelaje blanco en la base con puntas de color'
|
||||
);
|
||||
|
||||
insert into
|
||||
permissions (code)
|
||||
values
|
||||
('LOGIN'),
|
||||
('USERS_ADMINISTRATE'),
|
||||
('USERS_CREATE'),
|
||||
('USERS_EDIT'),
|
||||
('USERS_DISABLE'),
|
||||
('USERS_FORCE_RESET_PASSWORD'),
|
||||
('ANIMALS_ADMINISTRATE'),
|
||||
('ANIMALS_CREATE'),
|
||||
('ANIMALS_EDIT'),
|
||||
('ANIMALS_DISABLE'),
|
||||
('ANIMALS_SET_PUBLIC'),
|
||||
('ANIMAL_IMAGES_ADMINISTRATE'),
|
||||
('ANIMAL_IMAGES_UPLOAD'),
|
||||
('ANIMAL_IMAGES_EDIT'),
|
||||
('ANIMAL_IMAGES_DISABLE'),
|
||||
('ANIMAL_IMAGES_SET_PUBLIC'),
|
||||
('ANIMAL_COMMENTS_ADMINISTRATE'),
|
||||
('ANIMAL_COMMENTS_CREATE'),
|
||||
('ANIMAL_COMMENTS_EDIT'),
|
||||
('ANIMAL_COMMENTS_DISABLE'),
|
||||
('ANIMAL_COMMENTS_SET_PUBLIC'),
|
||||
('ANIMAL_ALERTS_ADMINISTRATE'),
|
||||
('ANIMAL_ALERTS_CREATE'),
|
||||
('ANIMAL_ALERTS_EDIT'),
|
||||
('ANIMAL_ALERTS_DISABLE'),
|
||||
('SETTLEMENTS_ADMINISTRATE'),
|
||||
('SETTLEMENTS_CREATE'),
|
||||
('SETTLEMENTS_EDIT'),
|
||||
('SETTLEMENTS_DISABLE');
|
||||
|
||||
insert into
|
||||
groups (code)
|
||||
values
|
||||
('ADMINISTRATORS'),
|
||||
('WORKERS'),
|
||||
('VOLUNTEERS'),
|
||||
('ADOPTERS');
|
||||
|
||||
insert into
|
||||
users (id, name, surnames, email)
|
||||
values
|
||||
(
|
||||
1,
|
||||
'Albert',
|
||||
'Gutiérrez Muñoz',
|
||||
'albertgmu@gmail.com'
|
||||
);
|
||||
|
||||
insert into
|
||||
user_accounts (user_id, username, password)
|
||||
values
|
||||
(1, 'devadmin', 'fe452152faec60d73c3f00c3bb985fe9');
|
||||
Binary file not shown.
@@ -0,0 +1,170 @@
|
||||
-- drop database if exists settlements;
|
||||
-- create database settlements;
|
||||
drop type if exists alert_types cascade;
|
||||
|
||||
create type alert_types as enum ('info', 'low', 'medium', 'high', 'ultra');
|
||||
|
||||
drop type if exists message_types cascade;
|
||||
|
||||
create type message_types as enum ('info', 'alert');
|
||||
|
||||
drop type if exists animal_sexs cascade;
|
||||
|
||||
create type animal_sexs as enum ('female', 'male', 'unknown');
|
||||
|
||||
drop table if exists users cascade;
|
||||
|
||||
drop table if exists user_accounts cascade;
|
||||
|
||||
drop table if exists permissions cascade;
|
||||
|
||||
drop table if exists groups cascade;
|
||||
|
||||
drop table if exists user_groups cascade;
|
||||
|
||||
drop table if exists user_permissions cascade;
|
||||
|
||||
drop table if exists group_permissions cascade;
|
||||
|
||||
drop table if exists user_groups cascade;
|
||||
|
||||
drop table if exists user_sessions cascade;
|
||||
|
||||
drop table if exists user_recover_requests cascade;
|
||||
|
||||
drop table if exists settlements cascade;
|
||||
|
||||
drop table if exists animals cascade;
|
||||
|
||||
drop table if exists animal_comments cascade;
|
||||
|
||||
drop table if exists animal_alerts cascade;
|
||||
|
||||
drop table if exists animal_images cascade;
|
||||
|
||||
drop table if exists animal_coats cascade;
|
||||
|
||||
create table users (
|
||||
id bigint generated by default as identity primary key,
|
||||
name varchar,
|
||||
surnames varchar,
|
||||
email varchar
|
||||
);
|
||||
|
||||
create table user_accounts (
|
||||
id bigint generated by default as identity primary key,
|
||||
user_id bigint references users (id),
|
||||
username varchar unique not null,
|
||||
password varchar not null,
|
||||
attempts smallint default 0,
|
||||
locked bool default false,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table permissions (
|
||||
id bigint generated by default as identity primary key,
|
||||
code varchar unique not null,
|
||||
description varchar default null
|
||||
);
|
||||
|
||||
create table groups (
|
||||
id bigint generated by default as identity primary key,
|
||||
code varchar unique not null,
|
||||
description varchar default null
|
||||
);
|
||||
|
||||
create table user_groups (
|
||||
user_id bigint references users (id),
|
||||
group_id bigint references groups (id)
|
||||
);
|
||||
|
||||
create table user_permissions (
|
||||
user_id bigint references users (id),
|
||||
permission_id bigint references permissions (id)
|
||||
);
|
||||
|
||||
create table group_permissions (
|
||||
group_id bigint references groups (id),
|
||||
permission_id bigint references permissions (id)
|
||||
);
|
||||
|
||||
create table user_sessions (
|
||||
id bigint generated by default as identity primary key,
|
||||
user_id bigint not null references users (id),
|
||||
token varchar not null unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table user_recover_requests (
|
||||
id bigint generated by default as identity primary key,
|
||||
user_id bigint not null references users (id),
|
||||
token varchar not null unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table settlements (
|
||||
id bigint generated by default as identity primary key,
|
||||
name varchar not null unique,
|
||||
address varchar not null unique,
|
||||
created_at timestamp not null default current_timestamp,
|
||||
last_done timestamp default null,
|
||||
last_done_by bigint references users (id),
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_coats (
|
||||
id bigint generated by default as identity primary key,
|
||||
code varchar unique not null,
|
||||
description varchar default null
|
||||
);
|
||||
|
||||
create table animals (
|
||||
id bigint generated by default as identity primary key,
|
||||
name varchar not null,
|
||||
microchip varchar default null,
|
||||
coat bigint not null references animal_coats (id),
|
||||
sex animal_sexs default 'unknown',
|
||||
settlement_id bigint references settlements (id),
|
||||
has_ear_mark bool default false,
|
||||
controlled bool default false,
|
||||
castrated bool default false,
|
||||
adopted bool default false,
|
||||
friendly bool default null,
|
||||
friendly_children bool default null,
|
||||
friendly_dogs bool default null,
|
||||
first_view timestamp default null,
|
||||
last_view timestamp default null,
|
||||
created_at timestamp not null default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_comments (
|
||||
id bigint generated by default as identity primary key,
|
||||
animal_id bigint not null references animals (id),
|
||||
type message_types default 'info',
|
||||
message varchar not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
public bool default false,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_alerts (
|
||||
id bigint generated by default as identity primary key,
|
||||
animal_id bigint not null references animals (id),
|
||||
type alert_types default 'high',
|
||||
comment varchar not null,
|
||||
created_at timestamp default current_timestamp,
|
||||
active bool default true
|
||||
);
|
||||
|
||||
create table animal_images (
|
||||
id bigint generated by default as identity primary key,
|
||||
animal_id bigint not null references animals (id),
|
||||
image varchar not null unique,
|
||||
created_at timestamp default current_timestamp,
|
||||
is_primary bool default false,
|
||||
public bool default false,
|
||||
active bool default true
|
||||
);
|
||||
@@ -0,0 +1,92 @@
|
||||
truncate table animal_coats cascade;
|
||||
|
||||
truncate table permissions cascade;
|
||||
|
||||
truncate table groups cascade;
|
||||
|
||||
truncate table users cascade;
|
||||
|
||||
truncate table user_accounts cascade;
|
||||
|
||||
insert into
|
||||
animal_coats (code)
|
||||
values
|
||||
('NEGRO'),
|
||||
('NARANJA'),
|
||||
('BLANCO'),
|
||||
('CHOCOLATE');
|
||||
|
||||
insert into
|
||||
animal_coats (code, description)
|
||||
values
|
||||
('CAREY', 'Mezcla irregular de negro y rojo'),
|
||||
('AZUL', 'Gris diluido'),
|
||||
('CANELA', 'Marrón claro con toque dorado'),
|
||||
('LILA', 'Crema con tono lavanda'),
|
||||
('CREMA', 'Naranja pálido'),
|
||||
('CALICO', 'Combina blanco, negro y naranja'),
|
||||
('ATIGRADO', 'Con rayas o espirales definidas'),
|
||||
(
|
||||
'COLORPOINT',
|
||||
'Cuerpo claro con extremidades oscuras'
|
||||
),
|
||||
(
|
||||
'AHUMADO',
|
||||
'Pelaje blanco en la base con puntas de color'
|
||||
);
|
||||
|
||||
insert into
|
||||
permissions (code)
|
||||
values
|
||||
('LOGIN'),
|
||||
('USERS_ADMINISTRATE'),
|
||||
('USERS_CREATE'),
|
||||
('USERS_EDIT'),
|
||||
('USERS_DISABLE'),
|
||||
('USERS_FORCE_RESET_PASSWORD'),
|
||||
('ANIMALS_ADMINISTRATE'),
|
||||
('ANIMALS_CREATE'),
|
||||
('ANIMALS_EDIT'),
|
||||
('ANIMALS_DISABLE'),
|
||||
('ANIMALS_SET_PUBLIC'),
|
||||
('ANIMAL_IMAGES_ADMINISTRATE'),
|
||||
('ANIMAL_IMAGES_UPLOAD'),
|
||||
('ANIMAL_IMAGES_EDIT'),
|
||||
('ANIMAL_IMAGES_DISABLE'),
|
||||
('ANIMAL_IMAGES_SET_PUBLIC'),
|
||||
('ANIMAL_COMMENTS_ADMINISTRATE'),
|
||||
('ANIMAL_COMMENTS_CREATE'),
|
||||
('ANIMAL_COMMENTS_EDIT'),
|
||||
('ANIMAL_COMMENTS_DISABLE'),
|
||||
('ANIMAL_COMMENTS_SET_PUBLIC'),
|
||||
('ANIMAL_ALERTS_ADMINISTRATE'),
|
||||
('ANIMAL_ALERTS_CREATE'),
|
||||
('ANIMAL_ALERTS_EDIT'),
|
||||
('ANIMAL_ALERTS_DISABLE'),
|
||||
('SETTLEMENTS_ADMINISTRATE'),
|
||||
('SETTLEMENTS_CREATE'),
|
||||
('SETTLEMENTS_EDIT'),
|
||||
('SETTLEMENTS_DISABLE');
|
||||
|
||||
insert into
|
||||
groups (code)
|
||||
values
|
||||
('ADMINISTRATORS'),
|
||||
('WORKERS'),
|
||||
('VOLUNTEERS'),
|
||||
('ADOPTERS');
|
||||
|
||||
insert into
|
||||
users (id, name, surnames, email)
|
||||
values
|
||||
(
|
||||
1,
|
||||
'Albert',
|
||||
'Gutiérrez Muñoz',
|
||||
'albertgmu@gmail.com'
|
||||
);
|
||||
|
||||
insert into
|
||||
user_accounts (user_id, username, password)
|
||||
values
|
||||
(1, 'devadmin', encode (sha256 (''), 'hex'));
|
||||
Reference in New Issue
Block a user