Skip to content

feat: digest contributions into database and query it on /contributions endpoint #593

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

Merged
merged 13 commits into from
Sep 8, 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
21 changes: 0 additions & 21 deletions api/db/migrations/0000_new_lake.sql

This file was deleted.

48 changes: 48 additions & 0 deletions api/db/migrations/0000_sudden_doctor_doom.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
CREATE TABLE `contributions` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`record_imported_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`title` text NOT NULL,
`updated_at` text NOT NULL,
`url` text NOT NULL,
`type` text NOT NULL,
`run_id` text NOT NULL,
`activity_count` integer NOT NULL,
`repository_id` integer NOT NULL,
`contributor_id` integer NOT NULL,
FOREIGN KEY (`repository_id`) REFERENCES `repositories`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`contributor_id`) REFERENCES `contributors`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `contributors` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`record_imported_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`run_id` text DEFAULT 'initial-run-id' NOT NULL,
`name` text NOT NULL,
`username` text NOT NULL,
`url` text NOT NULL,
`avatar_url` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `projects` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`record_imported_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`name` text NOT NULL,
`slug` text NOT NULL,
`run_id` text DEFAULT 'initial-run-id' NOT NULL
);
--> statement-breakpoint
CREATE TABLE `repositories` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`record_imported_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`provider` text NOT NULL,
`owner` text NOT NULL,
`name` text NOT NULL,
`run_id` text DEFAULT 'initial-run-id' NOT NULL,
`project_id` integer NOT NULL,
FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE UNIQUE INDEX `contributions_url_unique` ON `contributions` (`url`);--> statement-breakpoint
CREATE UNIQUE INDEX `contributors_url_unique` ON `contributors` (`url`);--> statement-breakpoint
CREATE UNIQUE INDEX `projects_slug_unique` ON `projects` (`slug`);--> statement-breakpoint
CREATE UNIQUE INDEX `repositories_provider_owner_name_unique` ON `repositories` (`provider`,`owner`,`name`);
10 changes: 10 additions & 0 deletions api/db/migrations/0001_black_eternals.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE `contributor_repository_relation` (
`contributor_id` integer NOT NULL,
`repository_id` integer NOT NULL,
`record_imported_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`run_id` text DEFAULT 'initial-run-id' NOT NULL,
`score` integer NOT NULL,
PRIMARY KEY(`contributor_id`, `repository_id`),
FOREIGN KEY (`contributor_id`) REFERENCES `contributors`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`repository_id`) REFERENCES `repositories`(`id`) ON UPDATE no action ON DELETE no action
);
173 changes: 172 additions & 1 deletion api/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,180 @@
{
"version": "6",
"dialect": "sqlite",
"id": "ab1b512a-8ca8-44e1-b497-445465117250",
"id": "ba41012f-4495-42ff-ace1-61bd7eaef476",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"contributions": {
"name": "contributions",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"record_imported_at": {
"name": "record_imported_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"run_id": {
"name": "run_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"activity_count": {
"name": "activity_count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"repository_id": {
"name": "repository_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"contributor_id": {
"name": "contributor_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"contributions_url_unique": {
"name": "contributions_url_unique",
"columns": ["url"],
"isUnique": true
}
},
"foreignKeys": {
"contributions_repository_id_repositories_id_fk": {
"name": "contributions_repository_id_repositories_id_fk",
"tableFrom": "contributions",
"tableTo": "repositories",
"columnsFrom": ["repository_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
"contributions_contributor_id_contributors_id_fk": {
"name": "contributions_contributor_id_contributors_id_fk",
"tableFrom": "contributions",
"tableTo": "contributors",
"columnsFrom": ["contributor_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"contributors": {
"name": "contributors",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"record_imported_at": {
"name": "record_imported_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"run_id": {
"name": "run_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'initial-run-id'"
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"avatar_url": {
"name": "avatar_url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"contributors_url_unique": {
"name": "contributors_url_unique",
"columns": ["url"],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"projects": {
"name": "projects",
"columns": {
Expand Down
Loading
Loading