Merge pull request #68 from twentyhq/cbo-add-user-to-workspaces-on-signup
Assign user to workspace on signin
This commit is contained in:
@ -120,3 +120,24 @@ array_relationships:
|
||||
table:
|
||||
name: user_providers
|
||||
schema: auth
|
||||
- name: workspace_member
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: user_id
|
||||
table:
|
||||
name: workspace_members
|
||||
schema: public
|
||||
event_triggers:
|
||||
- name: user-created
|
||||
definition:
|
||||
enable_manual: false
|
||||
insert:
|
||||
columns: '*'
|
||||
retry_conf:
|
||||
interval_sec: 10
|
||||
num_retries: 0
|
||||
timeout_sec: 60
|
||||
webhook: '{{HASURA_EVENT_HANDLER_URL}}'
|
||||
headers:
|
||||
- name: secret-header
|
||||
value: secret
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
table:
|
||||
name: workspace_members
|
||||
schema: public
|
||||
@ -8,4 +8,5 @@
|
||||
- "!include auth_users.yaml"
|
||||
- "!include public_companies.yaml"
|
||||
- "!include public_people.yaml"
|
||||
- "!include public_workspace_members.yaml"
|
||||
- "!include public_workspaces.yaml"
|
||||
|
||||
10
hasura/migrations/default/1682338781740_squashed/down.sql
Normal file
10
hasura/migrations/default/1682338781740_squashed/down.sql
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
alter table "public"."workspaces" rename column "domain_name" to "name";
|
||||
|
||||
alter table "public"."workspaces" add constraint "workspaces_domain_name_key" unique (domain_name);
|
||||
alter table "public"."workspaces" alter column "domain_name" drop not null;
|
||||
alter table "public"."workspaces" add column "domain_name" text;
|
||||
|
||||
|
||||
|
||||
DROP TABLE "public"."workspace_members";
|
||||
55
hasura/migrations/default/1682338781740_squashed/up.sql
Normal file
55
hasura/migrations/default/1682338781740_squashed/up.sql
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
CREATE TABLE "public"."workspace_members" ("id" serial NOT NULL, "user_id" uuid NOT NULL, "workspace_id" integer NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id") ON UPDATE restrict ON DELETE restrict, FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON UPDATE restrict ON DELETE restrict, UNIQUE ("id"), UNIQUE ("user_id"));
|
||||
|
||||
alter table "public"."workspace_members" add column "created_at" timestamptz
|
||||
not null default now();
|
||||
|
||||
alter table "public"."workspace_members" add column "updated_at" timestamptz
|
||||
not null default now();
|
||||
|
||||
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
|
||||
RETURNS TRIGGER AS $$
|
||||
DECLARE
|
||||
_new record;
|
||||
BEGIN
|
||||
_new := NEW;
|
||||
_new."updated_at" = NOW();
|
||||
RETURN _new;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE TRIGGER "set_public_workspace_members_updated_at"
|
||||
BEFORE UPDATE ON "public"."workspace_members"
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
|
||||
COMMENT ON TRIGGER "set_public_workspace_members_updated_at" ON "public"."workspace_members"
|
||||
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
|
||||
|
||||
alter table "public"."workspace_members" add column "deleted_at" timestamptz
|
||||
null;
|
||||
|
||||
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_deleted_at"()
|
||||
RETURNS TRIGGER AS $$
|
||||
DECLARE
|
||||
_new record;
|
||||
BEGIN
|
||||
_new := NEW;
|
||||
_new."deleted_at" = NOW();
|
||||
RETURN _new;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
CREATE TRIGGER "set_public_workspace_members_deleted_at"
|
||||
BEFORE UPDATE ON "public"."workspace_members"
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE "public"."set_current_timestamp_deleted_at"();
|
||||
COMMENT ON TRIGGER "set_public_workspace_members_deleted_at" ON "public"."workspace_members"
|
||||
IS 'trigger to set value of column "deleted_at" to current timestamp on row update';
|
||||
|
||||
alter table "public"."workspaces" add column "domain_name" text
|
||||
null unique;
|
||||
|
||||
alter table "public"."workspaces" drop column "domain_name" cascade;
|
||||
|
||||
alter table "public"."workspaces" rename column "name" to "domain_name";
|
||||
|
||||
alter table "public"."workspaces" add column "deleted_at" Timestamp
|
||||
null;
|
||||
Reference in New Issue
Block a user