|
| 1 | +CREATE TABLE IF NOT EXISTS "contributions" ( |
| 2 | + "id" text PRIMARY KEY NOT NULL, |
| 3 | + "record_imported_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 4 | + "title" text NOT NULL, |
| 5 | + "updated_at" text NOT NULL, |
| 6 | + "url" text NOT NULL, |
| 7 | + "type" text NOT NULL, |
| 8 | + "run_id" text NOT NULL, |
| 9 | + "activity_count" integer NOT NULL, |
| 10 | + "repository_id" text NOT NULL, |
| 11 | + "contributor_id" text NOT NULL, |
| 12 | + CONSTRAINT "contributions_url_unique" UNIQUE("url") |
| 13 | +); |
| 14 | +--> statement-breakpoint |
| 15 | +CREATE TABLE IF NOT EXISTS "contributor_repository_relation" ( |
| 16 | + "contributor_id" text NOT NULL, |
| 17 | + "repository_id" text NOT NULL, |
| 18 | + "record_imported_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 19 | + "run_id" text DEFAULT 'initial-run-id' NOT NULL, |
| 20 | + "score" integer NOT NULL, |
| 21 | + CONSTRAINT "contributor_repository_relation_pk" PRIMARY KEY("contributor_id","repository_id") |
| 22 | +); |
| 23 | +--> statement-breakpoint |
| 24 | +CREATE TABLE IF NOT EXISTS "contributors" ( |
| 25 | + "id" text PRIMARY KEY NOT NULL, |
| 26 | + "record_imported_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 27 | + "run_id" text DEFAULT 'initial-run-id' NOT NULL, |
| 28 | + "name" text NOT NULL, |
| 29 | + "username" text NOT NULL, |
| 30 | + "url" text NOT NULL, |
| 31 | + "avatar_url" text NOT NULL, |
| 32 | + CONSTRAINT "contributors_url_unique" UNIQUE("url") |
| 33 | +); |
| 34 | +--> statement-breakpoint |
| 35 | +CREATE TABLE IF NOT EXISTS "projects" ( |
| 36 | + "id" text PRIMARY KEY NOT NULL, |
| 37 | + "record_imported_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 38 | + "name" text NOT NULL, |
| 39 | + "run_id" text DEFAULT 'initial-run-id' NOT NULL |
| 40 | +); |
| 41 | +--> statement-breakpoint |
| 42 | +CREATE TABLE IF NOT EXISTS "repositories" ( |
| 43 | + "id" text PRIMARY KEY NOT NULL, |
| 44 | + "record_imported_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL, |
| 45 | + "provider" text NOT NULL, |
| 46 | + "owner" text NOT NULL, |
| 47 | + "name" text NOT NULL, |
| 48 | + "run_id" text DEFAULT 'initial-run-id' NOT NULL, |
| 49 | + "project_id" text NOT NULL, |
| 50 | + "stars" integer NOT NULL, |
| 51 | + CONSTRAINT "repositories_provider_owner_name_unique" UNIQUE("provider","owner","name") |
| 52 | +); |
| 53 | +--> statement-breakpoint |
| 54 | +DO $$ BEGIN |
| 55 | + ALTER TABLE "contributions" ADD CONSTRAINT "contributions_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action; |
| 56 | +EXCEPTION |
| 57 | + WHEN duplicate_object THEN null; |
| 58 | +END $$; |
| 59 | +--> statement-breakpoint |
| 60 | +DO $$ BEGIN |
| 61 | + ALTER TABLE "contributions" ADD CONSTRAINT "contributions_contributor_id_contributors_id_fk" FOREIGN KEY ("contributor_id") REFERENCES "public"."contributors"("id") ON DELETE no action ON UPDATE no action; |
| 62 | +EXCEPTION |
| 63 | + WHEN duplicate_object THEN null; |
| 64 | +END $$; |
| 65 | +--> statement-breakpoint |
| 66 | +DO $$ BEGIN |
| 67 | + ALTER TABLE "contributor_repository_relation" ADD CONSTRAINT "contributor_repository_relation_contributor_id_contributors_id_fk" FOREIGN KEY ("contributor_id") REFERENCES "public"."contributors"("id") ON DELETE no action ON UPDATE no action; |
| 68 | +EXCEPTION |
| 69 | + WHEN duplicate_object THEN null; |
| 70 | +END $$; |
| 71 | +--> statement-breakpoint |
| 72 | +DO $$ BEGIN |
| 73 | + ALTER TABLE "contributor_repository_relation" ADD CONSTRAINT "contributor_repository_relation_repository_id_repositories_id_fk" FOREIGN KEY ("repository_id") REFERENCES "public"."repositories"("id") ON DELETE no action ON UPDATE no action; |
| 74 | +EXCEPTION |
| 75 | + WHEN duplicate_object THEN null; |
| 76 | +END $$; |
| 77 | +--> statement-breakpoint |
| 78 | +DO $$ BEGIN |
| 79 | + ALTER TABLE "repositories" ADD CONSTRAINT "repositories_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE no action ON UPDATE no action; |
| 80 | +EXCEPTION |
| 81 | + WHEN duplicate_object THEN null; |
| 82 | +END $$; |
0 commit comments