Created
October 18, 2019 12:46
-
-
Save joffilyfe/83ade086a38f827ddfcbe84f8f7694ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create schema api; | |
CREATE TYPE api.EVENT_STATE_ENUM AS ENUM ('success', 'fail'); | |
-- document table | |
CREATE TABLE api.documents( | |
id CHAR(23) PRIMARY KEY | |
); | |
-- validations events | |
CREATE TABLE api.validations( | |
id SERIAL PRIMARY KEY, | |
entity varchar(100) NOT NULL, | |
entity_id CHAR(23) NOT NULL, | |
validation varchar(50) NOT NULL default 'basic', | |
validation_group varchar(10) NOT NULL, | |
validation_errors JSON, | |
state api.EVENT_STATE_ENUM, | |
timestamp timestamp NOT NULL default NOW() | |
); | |
-- api.validations indexes | |
CREATE INDEX api_validations_timestamp ON api.validations(timestamp); | |
CREATE INDEX api_validations_entity_id ON api.validations(entity_id); | |
-- INSERTION TEST | |
INSERT INTO api.validations (entity, entity_id, validation, validation_group, state) VALUES ('document', 'd18joigYlxmIfZ3SbSnfdAs', 'basic', 'random_key', 'success'); | |
INSERT INTO api.validations (entity, entity_id, validation, validation_group, state) VALUES ('document', 'd18joigYlxmIfZ3SbSnfdAs', 'assets validation', 'random_key', 'success'); | |
INSERT INTO api.validations (entity, entity_id, validation, validation_group, state) VALUES ('document', 'o3J2XaUa9qQVrg5sC8928JS', 'basic', 'random_key', 'success'); | |
INSERT INTO api.validations (entity, entity_id, validation, validation_group, state) VALUES ('document', 'o3J2XaUa9qQVrg5sC8928JS', 'assets validation', 'random_key', 'success'); | |
-- Basic selects | |
SELECT * FROM api.validations; | |
SELECT * FROM api.documents d JOIN api.validations v ON d.id = v.entity_id WHERE entity = 'document'; | |
-- Read only user | |
create role web_anon nologin; | |
grant usage on schema api to web_anon; | |
grant select on api.validations to web_anon; | |
grant select on api.documents to web_anon; | |
create role authenticator noinherit login password '12345678'; | |
grant web_anon to authenticator; | |
-- Read and Write user | |
create role api_validations_user nologin; | |
grant api_validations_user to authenticator; | |
grant usage on schema api to api_validations_user; | |
grant all on api.validations to api_validations_user; | |
grant usage, select on sequence api.validations_id_seq to api_validations_user; | |
-- eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYXBpX3ZhbGlkYXRpb25zX3VzZXIifQ.DjEMMrpQEe9WSyCs0RjMrzXeIZ3ATPS0OfWAd1X6MTM | |
docker run -p 9090:8080 -e SWAGGER_JSON=/Users/joffily/Downloads/rest/sw/swagger.json -v /Users/joffily/Downloads/rest/sw:/foo --name swagger swaggerapi/swagger-ui |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment