Skip to content

Instantly share code, notes, and snippets.

@ratul0
Created August 10, 2024 10:42
Show Gist options
  • Save ratul0/f177744fa3517a76ac9a591744bbfc89 to your computer and use it in GitHub Desktop.
Save ratul0/f177744fa3517a76ac9a591744bbfc89 to your computer and use it in GitHub Desktop.
CREATE TABLE users ( id SERIAL PRIMARY KEY, cognito_id VARCHAR(255) UNIQUE NOT NULL );
CREATE TABLE applications ( id SERIAL PRIMARY KEY, app_id VARCHAR(50) UNIQUE NOT NULL, name VARCHAR(100) NOT NULL );
CREATE TABLE roles ( id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, application_id INTEGER REFERENCES applications(id) );
CREATE TABLE permissions ( id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, application_id INTEGER REFERENCES applications(id) );
CREATE TABLE user_roles ( user_id INTEGER REFERENCES users(id), role_id INTEGER REFERENCES roles(id), PRIMARY KEY (user_id, role_id) );
CREATE TABLE role_permissions ( role_id INTEGER REFERENCES roles(id), permission_id INTEGER REFERENCES permissions(id), PRIMARY KEY (role_id, permission_id) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment