Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/server/database-grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ ALTER TABLE connectors.connector_write OWNER TO test_owner;
ALTER TABLE connectors.project_connection OWNER TO test_owner;
ALTER TABLE copies.copy OWNER TO test_owner;
ALTER TABLE copies.copy_proposal OWNER TO test_owner;
ALTER TABLE copies.copy_proposal_source OWNER TO test_owner;
ALTER TABLE copies.copy_run OWNER TO test_owner;
ALTER TABLE copies.copy_source OWNER TO test_owner;
ALTER TABLE copies.copy_table_left OWNER TO test_owner;
ALTER TABLE copies.project_copy OWNER TO test_owner;
ALTER TABLE drizzle.__drizzle_migrations OWNER TO test_owner;
ALTER SEQUENCE drizzle.__drizzle_migrations_id_seq OWNER TO test_owner;
Expand Down Expand Up @@ -341,7 +344,9 @@ GRANT SELECT,INSERT,DELETE ON TABLE connectors.project_connection TO hub_company
-- Capacity 2, U2, with the founder's word in the pull request of its own (data D11): a company's
-- routes and its copies' runs turn a copy on, hold its run's lease and save where its pass stands,
-- record each run and keep the newest, and release a copy to a Projeto and take it back.
GRANT SELECT,INSERT ON TABLE copies.copy TO hub_company;
-- O Sync de qualquer conector, with the founder's word in the pull request of its own (data D11):
-- Desligar ends, in the transaction that deletes the connection, the copy left with no source.
GRANT SELECT,INSERT,DELETE ON TABLE copies.copy TO hub_company;
GRANT UPDATE(claim_token) ON TABLE copies.copy TO hub_company;
GRANT UPDATE(claimed_until) ON TABLE copies.copy TO hub_company;
GRANT UPDATE(pass) ON TABLE copies.copy TO hub_company;
Expand All @@ -356,13 +361,27 @@ GRANT UPDATE(last_run_id) ON TABLE copies.copy TO hub_company;
GRANT SELECT,INSERT ON TABLE copies.copy_proposal TO hub_company;
GRANT UPDATE(state) ON TABLE copies.copy_proposal TO hub_company;
GRANT UPDATE(copy_id) ON TABLE copies.copy_proposal TO hub_company;
-- O Sync de qualquer conector, with the founder's word in the pull request of its own (data D11): the
-- Builder's run proposes a copy over several connections; a proposal's source leaves by cascade.
GRANT SELECT,INSERT ON TABLE copies.copy_proposal_source TO hub_company;
GRANT SELECT,INSERT,DELETE ON TABLE copies.copy_run TO hub_company;
GRANT UPDATE(ended_at) ON TABLE copies.copy_run TO hub_company;
GRANT UPDATE(outcome) ON TABLE copies.copy_run TO hub_company;
GRANT UPDATE(reason) ON TABLE copies.copy_run TO hub_company;
GRANT UPDATE(pages) ON TABLE copies.copy_run TO hub_company;
GRANT UPDATE(read) ON TABLE copies.copy_run TO hub_company;
GRANT UPDATE(written) ON TABLE copies.copy_run TO hub_company;
-- O Sync de qualquer conector, with the founder's word in the pull request of its own (data D11): a
-- copy's runs read and save where each of its connections stands and until when the provider asked
-- it to wait; a source leaves by cascade. Desligar writes down the table of a copy that ended while
-- the company's database did not answer, and drains the row once the table is dropped.
GRANT SELECT,INSERT ON TABLE copies.copy_source TO hub_company;
GRANT UPDATE(pass) ON TABLE copies.copy_source TO hub_company;
GRANT UPDATE(pass_started_at) ON TABLE copies.copy_source TO hub_company;
GRANT UPDATE("position") ON TABLE copies.copy_source TO hub_company;
GRANT UPDATE(watermark) ON TABLE copies.copy_source TO hub_company;
GRANT UPDATE(wait_until) ON TABLE copies.copy_source TO hub_company;
GRANT SELECT,INSERT,DELETE ON TABLE copies.copy_table_left TO hub_company;
GRANT SELECT,INSERT,DELETE ON TABLE copies.project_copy TO hub_company;
GRANT SELECT ON TABLE drizzle.__drizzle_migrations TO hub_runtime;
GRANT SELECT,INSERT ON TABLE hub.starts TO hub_runtime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CREATE TABLE "copies"."copy_proposal_source" (
"company_id" text NOT NULL,
"proposal_id" uuid,
"connector_id" text NOT NULL,
"connection_id" uuid,
CONSTRAINT "copy_proposal_source_pkey" PRIMARY KEY("proposal_id","connection_id")
);
--> statement-breakpoint
ALTER TABLE "copies"."copy_proposal_source" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "copies"."copy_source" (
"company_id" text NOT NULL,
"copy_id" uuid,
"connector_id" text NOT NULL,
"connection_id" uuid,
"account_ref" text,
"pass" integer DEFAULT 0 NOT NULL,
"pass_started_at" timestamp with time zone,
"position" jsonb,
"watermark" timestamp with time zone,
"wait_until" timestamp with time zone,
"created_at" timestamp with time zone NOT NULL,
CONSTRAINT "copy_source_pkey" PRIMARY KEY("copy_id","connection_id"),
CONSTRAINT "copy_source_copy_id_account_ref_key" UNIQUE("copy_id","account_ref"),
CONSTRAINT "copy_source_position" CHECK ("position" IS NULL OR jsonb_typeof("position") = 'object')
);
--> statement-breakpoint
ALTER TABLE "copies"."copy_source" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
CREATE TABLE "copies"."copy_table_left" (
"company_id" text,
"copy_id" uuid,
"name" text NOT NULL,
CONSTRAINT "copy_table_left_pkey" PRIMARY KEY("company_id","copy_id"),
CONSTRAINT "copy_table_left_name" CHECK ("name" ~ '^[a-z][a-z0-9_]{0,39}$')
);
--> statement-breakpoint
ALTER TABLE "copies"."copy_table_left" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
ALTER TABLE "copies"."copy_proposal" ADD COLUMN "proved_calls" integer;--> statement-breakpoint
ALTER TABLE "copies"."copy_proposal_source" ADD CONSTRAINT "copy_proposal_source_proposal_fkey" FOREIGN KEY ("proposal_id") REFERENCES "copies"."copy_proposal"("id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "copies"."copy_proposal_source" ADD CONSTRAINT "copy_proposal_source_connection_fkey" FOREIGN KEY ("company_id","connector_id","connection_id") REFERENCES "connectors"."connection"("company_id","connector_id","id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "copies"."copy_source" ADD CONSTRAINT "copy_source_copy_fkey" FOREIGN KEY ("company_id","copy_id") REFERENCES "copies"."copy"("company_id","id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "copies"."copy_source" ADD CONSTRAINT "copy_source_connection_fkey" FOREIGN KEY ("company_id","connector_id","connection_id") REFERENCES "connectors"."connection"("company_id","connector_id","id") ON DELETE CASCADE;--> statement-breakpoint
ALTER TABLE "copies"."copy_table_left" ADD CONSTRAINT "copy_table_left_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "auth"."company"("id") ON DELETE CASCADE;--> statement-breakpoint
CREATE POLICY "company_all" ON "copies"."copy_proposal_source" AS PERMISSIVE FOR ALL TO "hub_company" USING (company_id = nullif(current_setting('conexus.company_id', true), '')) WITH CHECK (company_id = nullif(current_setting('conexus.company_id', true), ''));--> statement-breakpoint
CREATE POLICY "company_all" ON "copies"."copy_source" AS PERMISSIVE FOR ALL TO "hub_company" USING (company_id = nullif(current_setting('conexus.company_id', true), '')) WITH CHECK (company_id = nullif(current_setting('conexus.company_id', true), ''));--> statement-breakpoint
CREATE POLICY "company_all" ON "copies"."copy_table_left" AS PERMISSIVE FOR ALL TO "hub_company" USING (company_id = nullif(current_setting('conexus.company_id', true), '')) WITH CHECK (company_id = nullif(current_setting('conexus.company_id', true), ''));
Loading
Loading