Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add migrations for the updated spans table with project id #152

Merged
merged 1 commit into from
Nov 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ CREATE TABLE IF NOT EXISTS "labeling_queue_data" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"queue_id" uuid DEFAULT gen_random_uuid() NOT NULL,
"data" jsonb NOT NULL,
"action" jsonb NOT NULL
"action" jsonb NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a foreign key constraint for the 'span_id' column to ensure referential integrity with the 'spans' table.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion overall, but for us spans are written asynchronously, so they may not be there by the time we write to this table

"span_id" uuid NOT NULL
);
--> statement-breakpoint
ALTER TABLE "dataset_datapoints" ALTER COLUMN "target" DROP NOT NULL;--> statement-breakpoint
Expand Down
29 changes: 29 additions & 0 deletions frontend/lib/db/migrations/0003_cultured_tinkerer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ALTER TABLE "labels" DROP CONSTRAINT "trace_tags_span_id_fkey";
--> statement-breakpoint
/*
[SOLVED]
Unfortunately in current drizzle-kit version we can't automatically get name for primary key.
We are working on making it available!

Meanwhile you can:
1. Check pk name in your database, by running
SELECT constraint_name FROM information_schema.table_constraints
WHERE table_schema = 'public'
AND table_name = 'spans'
AND constraint_type = 'PRIMARY KEY';
2. Uncomment code below and paste pk name manually

Hope to release this update as soon as possible
*/

ALTER TABLE "spans" DROP CONSTRAINT "spans_pkey";--> statement-breakpoint
ALTER TABLE "spans" ADD COLUMN "project_id" uuid NOT NULL;--> statement-breakpoint
ALTER TABLE "spans" ADD CONSTRAINT "spans_pkey" PRIMARY KEY("span_id","project_id");--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "spans" ADD CONSTRAINT "spans_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE cascade;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "spans_project_id_idx" ON "spans" USING btree ("project_id");--> statement-breakpoint
ALTER TABLE "spans" ADD CONSTRAINT "unique_span_id_project_id" UNIQUE("span_id","project_id");
12 changes: 6 additions & 6 deletions frontend/lib/db/migrations/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "4bf43179-5f48-4c3e-b1f0-033007c3a0c9",
"id": "326ba2ca-6925-4d69-8416-1a7691a8bcfd",
"prevId": "a7f4ca0c-430b-49f5-93d4-09d1ab968dac",
"version": "7",
"dialect": "postgresql",
Expand Down Expand Up @@ -742,15 +742,15 @@
"notNull": true,
"default": "gen_random_uuid()"
},
"data": {
"name": "data",
"action": {
"name": "action",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"action": {
"name": "action",
"type": "jsonb",
"span_id": {
"name": "span_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
}
Expand Down
Loading