Skip to content

Commit

Permalink
fix: script do esquema e permissões #64
Browse files Browse the repository at this point in the history
  • Loading branch information
tacianosilva committed May 2, 2023
1 parent 7d41888 commit 0279149
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 76 deletions.
59 changes: 0 additions & 59 deletions .circleci/config.yml

This file was deleted.

13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,23 @@ CREATE DATABASE apf_db
TABLESPACE = pg_default
CONNECTION LIMIT = -1
IS_TEMPLATE = False;
```

Por algum motivo, o JPA não está criando o banco de dados automaticamente. Desta forma, gerei o esquema relacional em `create.sql` e executei manualmente via PgAdmin. Desta forma, foi necessário executar comandos de permissões para o usuário `apf_user` do banco de dados `apf_db`.
```sql
GRANT ALL PRIVILEGES ON DATABASE apf_db TO apf_user;

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to apf_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public to apf_user;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public to apf_user;
```

Como os testes não estavam executando com a criação do esquema, essa parte foi removida. Ajustamos o nome da tabela `user` para `users`, pois o nome `user` é uma *palavra reservada* do Postgres.
```sql
CREATE SCHEMA IF NOT EXISTS apf
AUTHORIZATION apf_user;
```


2. Povoamento do Banco de Dados
```sql
INSERT INTO role VALUES (1,'ADMIN');
Expand Down
276 changes: 276 additions & 0 deletions create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@

create table attribution (
attrib_id serial not null,
attrib_name varchar(255),
primary key (attrib_id)
);

create table data_function (
data_id bigserial not null,
det int8,
description varchar(255),
name varchar(255) not null,
ret int8,
type varchar(255) not null,
project_id int8,
user_story_id int8,
primary key (data_id)
);

create table member (
member_id bigserial not null,
created_on date not null,
attrib_id int4 not null,
project_id int8 not null,
user_id int8 not null,
primary key (member_id)
);

create table project (
project_id bigserial not null,
active int4,
created_on date not null,
description varchar(255) not null,
is_private boolean not null,
name varchar(255),
primary key (project_id)
);

create table role (
role_id serial not null,
role_name varchar(255),
primary key (role_id)
);

create table transaction_function (
trans_id bigserial not null,
det int4,
description varchar(255),
ftr int4,
name varchar(255) not null,
type varchar(255) not null,
project_id int8,
user_story_id int8,
primary key (trans_id)
);

create table user_role (
user_id int8 not null,
role_id int4 not null,
primary key (user_id, role_id)
);

create table user_story (
user_story_id bigserial not null,
description varchar(255),
name varchar(255),
project_id int8 not null,
primary key (user_story_id)
);

create table users (
user_id bigserial not null,
active int4,
email varchar(255),
last_name varchar(255),
name varchar(255),
password varchar(255),
primary key (user_id)
);

alter table attribution
add constraint UK_ifqougpv1g0br8g67hstq5kxo unique (attrib_name);

alter table project
add constraint UK_3k75vvu7mevyvvb5may5lj8k7 unique (name);

alter table role
add constraint UK_iubw515ff0ugtm28p8g3myt0h unique (role_name);

alter table data_function
add constraint FKre6qmiqtq8jycft6y8vabky55
foreign key (project_id)
references project;

alter table data_function
add constraint FKdlvokmcc2or8dq955n5yisrpo
foreign key (user_story_id)
references user_story;

alter table member
add constraint FKiiq8mj6y0sssha2n9dekhhha
foreign key (attrib_id)
references attribution;

alter table member
add constraint FKn4gkqnpww70e7vcyfh0lt2imn
foreign key (project_id)
references project;

alter table member
add constraint FKe6yo8tn29so0kdd1mw4qk8tgh
foreign key (user_id)
references users;

alter table transaction_function
add constraint FKiwg15idv7boxrkyjn8c961mll
foreign key (project_id)
references project;

alter table transaction_function
add constraint FK2cxqcksbnyda0ata54ubjne98
foreign key (user_story_id)
references user_story;

alter table user_role
add constraint FKa68196081fvovjhkek5m97n3y
foreign key (role_id)
references role;

alter table user_role
add constraint FKj345gk1bovqvfame88rcx7yyx
foreign key (user_id)
references users;

alter table user_story
add constraint FKwswc3uhx3p0yuscuxsqh2ywt
foreign key (project_id)
references project;

create table attribution (
attrib_id serial not null,
attrib_name varchar(255),
primary key (attrib_id)
);

create table data_function (
data_id bigserial not null,
det int8,
description varchar(255),
name varchar(255) not null,
ret int8,
type varchar(255) not null,
project_id int8,
user_story_id int8,
primary key (data_id)
);

create table member (
member_id bigserial not null,
created_on date not null,
attrib_id int4 not null,
project_id int8 not null,
user_id int8 not null,
primary key (member_id)
);

create table project (
project_id bigserial not null,
active int4,
created_on date not null,
description varchar(255) not null,
is_private boolean not null,
name varchar(255),
primary key (project_id)
);

create table role (
role_id serial not null,
role_name varchar(255),
primary key (role_id)
);

create table transaction_function (
trans_id bigserial not null,
det int4,
description varchar(255),
ftr int4,
name varchar(255) not null,
type varchar(255) not null,
project_id int8,
user_story_id int8,
primary key (trans_id)
);

create table user_role (
user_id int8 not null,
role_id int4 not null,
primary key (user_id, role_id)
);

create table user_story (
user_story_id bigserial not null,
description varchar(255),
name varchar(255),
project_id int8 not null,
primary key (user_story_id)
);

create table users (
user_id bigserial not null,
active int4,
email varchar(255),
last_name varchar(255),
name varchar(255),
password varchar(255),
primary key (user_id)
);

alter table attribution
add constraint UK_ifqougpv1g0br8g67hstq5kxo unique (attrib_name);

alter table project
add constraint UK_3k75vvu7mevyvvb5may5lj8k7 unique (name);

alter table role
add constraint UK_iubw515ff0ugtm28p8g3myt0h unique (role_name);

alter table data_function
add constraint FKre6qmiqtq8jycft6y8vabky55
foreign key (project_id)
references project;

alter table data_function
add constraint FKdlvokmcc2or8dq955n5yisrpo
foreign key (user_story_id)
references user_story;

alter table member
add constraint FKiiq8mj6y0sssha2n9dekhhha
foreign key (attrib_id)
references attribution;

alter table member
add constraint FKn4gkqnpww70e7vcyfh0lt2imn
foreign key (project_id)
references project;

alter table member
add constraint FKe6yo8tn29so0kdd1mw4qk8tgh
foreign key (user_id)
references users;

alter table transaction_function
add constraint FKiwg15idv7boxrkyjn8c961mll
foreign key (project_id)
references project;

alter table transaction_function
add constraint FK2cxqcksbnyda0ata54ubjne98
foreign key (user_story_id)
references user_story;

alter table user_role
add constraint FKa68196081fvovjhkek5m97n3y
foreign key (role_id)
references role;

alter table user_role
add constraint FKj345gk1bovqvfame88rcx7yyx
foreign key (user_id)
references users;

alter table user_story
add constraint FKwswc3uhx3p0yuscuxsqh2ywt
foreign key (project_id)
references project;
Loading

0 comments on commit 0279149

Please sign in to comment.