Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

0012_same_as_links.sql

27 lines1.2 KB

1-- Hand-written: evidence of a model's upstream identity is stored apart from
2-- the resolved link. Nullable columns are added in place so the catalog is
3-- not copied through a table rebuild.
4CREATE TABLE `provider_model_namespaces` (
5 `namespace` text NOT NULL,
6 `provider_id` text NOT NULL,
7 PRIMARY KEY (`namespace`, `provider_id`),
8 FOREIGN KEY (`provider_id`) REFERENCES `providers` (`id`) ON DELETE cascade
9);
10--> statement-breakpoint
11CREATE INDEX `provider_model_namespaces_providerId_idx`
12 ON `provider_model_namespaces` (`provider_id`);
13--> statement-breakpoint
14ALTER TABLE `models` ADD `upstream_provider` text;
15--> statement-breakpoint
16ALTER TABLE `models` ADD `upstream_source` text;
17--> statement-breakpoint
18ALTER TABLE `models` ADD `upstream_raw_id` text
19 CONSTRAINT `models_upstream_identity_pair`
20 CHECK ((`upstream_provider` IS NULL) = (`upstream_raw_id` IS NULL)
21 AND (`upstream_provider` IS NULL) = (`upstream_source` IS NULL));
22--> statement-breakpoint
23ALTER TABLE `models` ADD `same_as_model_id` text
24 REFERENCES `models` (`id`) ON DELETE set null
25 CONSTRAINT `models_sameAs_not_self` CHECK (`same_as_model_id` != `id`);
26--> statement-breakpoint
27CREATE INDEX `models_sameAsModelId_idx` ON `models` (`same_as_model_id`);