diff --git a/postgres-language-server.jsonc b/postgres-language-server.jsonc index f2a7801..1360d3a 100644 --- a/postgres-language-server.jsonc +++ b/postgres-language-server.jsonc @@ -19,7 +19,7 @@ "enabled": true }, "format": { - "enabled": false + "enabled": true }, "pglinter": { "enabled": false diff --git a/postgres/00_tables.sql b/postgres/00_tables.sql index f4132ef..bf8f01a 100644 --- a/postgres/00_tables.sql +++ b/postgres/00_tables.sql @@ -1,49 +1,56 @@ -CREATE TABLE user_account ( - id uuid UNIQUE NOT NULL DEFAULT uuidv7(), - full_name text NOT NULL, - password_hash text NOT NULL, - email text UNIQUE NOT NULL CHECK (email LIKE '%@%'), - created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - is_active boolean NOT NULL DEFAULT TRUE, - PRIMARY KEY (id) +create table user_account ( + id uuid unique not null default uuidv7(), + full_name text not null, + password_hash text not null, + email text + unique + not null + check (email like '%@%'), + created_at timestamp + not null + default current_timestamp, + is_active boolean not null default true, + primary key (id) ); -CREATE TABLE segment ( - id uuid UNIQUE NOT NULL DEFAULT uuidv7(), - name text NOT NULL, - description text +create table segment ( + id uuid unique not null default uuidv7(), + name text not null, + description text ); -CREATE TABLE startup ( - id uuid UNIQUE NOT NULL DEFAULT uuidv7(), - segment_id uuid REFERENCES segment(id), - name text NOT NULL, - cnpj text UNIQUE NOT NULL CHECK (length(cnpj) = 14), - description text, - city text NOT NULL, - state text NOT NULL, - created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (id) +create table startup ( + id uuid unique not null default uuidv7(), + segment_id uuid references segment (id), + name text not null, + cnpj text + unique + not null + check (length(cnpj) = 14), + description text, + city text not null, + state text not null, + created_at timestamp + not null + default current_timestamp, + primary key (id) ); -CREATE TABLE startup_membership ( - user_id uuid REFERENCES user_account(id) ON DELETE CASCADE, - startup_id uuid REFERENCES startup(id) ON DELETE CASCADE, - PRIMARY KEY (user_id, startup_id) +create table startup_membership ( + user_id uuid + references user_account (id) on DELETE cascade, + startup_id uuid + references startup (id) on DELETE cascade, + primary key (user_id, startup_id) ); -CREATE TYPE investor_kind AS enum ( - 'angel', - 'venture', - 'individual', - 'institutional' -); +create type investor_kind as enum ('angel', 'venture', 'individual', 'institutional'); -CREATE TABLE investor ( - id uuid UNIQUE NOT NULL DEFAULT uuidv7(), - user_id uuid REFERENCES user_account(id), - segment_id uuid REFERENCES segment(id), - kind investor_kind NOT NULL, - public_profile boolean NOT NULL DEFAULT TRUE, - PRIMARY KEY (id) -) +create table investor ( + id uuid unique not null default uuidv7(), + user_id uuid references user_account (id), + segment_id uuid references segment (id), + kind investor_kind not null, + public_profile boolean not null default true, + primary key (id) +); diff --git a/postgres/01_fuctions.sql b/postgres/01_fuctions.sql new file mode 100644 index 0000000..43b3564 --- /dev/null +++ b/postgres/01_fuctions.sql @@ -0,0 +1,13 @@ +create or replace function public.get_startup_members(p_startup_id uuid) +returns table ( + user_uuid uuid +) +language plpgsql +as $function$ +begin + return query + SELECT distinct sm.user_id + from public.startup_membership as sm + where sm.startup_id = p_startup_id; +END; +$function$;