Make Github stars dynamic and improve database init (#5000)

I extracted the init database logic into its own file. 
You can now run it with yarn database:init.
Added database entry for GitHub stars. 

Do you want me to remove the init route or is it used for something else
?

---------

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
Ady Beraud
2024-04-24 10:44:44 +03:00
committed by GitHub
parent fda0c3c93c
commit 0a7f82333b
27 changed files with 237 additions and 118 deletions

View File

@ -0,0 +1,8 @@
import { migrate } from '@/database/database';
export const migrateDatabase = async () => {
await migrate();
process.exit(0);
};
migrateDatabase();

View File

@ -1,4 +1,5 @@
import {
pgGithubStars,
pgIssueLabels,
pgIssues,
pgLabels,
@ -31,17 +32,19 @@ export const issueLabelModel = isSqliteDriver
? sqlLiteIssueLabels
: pgIssueLabels;
export type User = typeof sqlLiteUsers.$inferSelect;
export type PullRequest = typeof sqlLitePullRequests.$inferSelect;
export type Issue = typeof sqlLiteIssues.$inferSelect;
export type Label = typeof sqlLiteLabels.$inferSelect;
export type PullRequestLabel = typeof sqlLitePullRequestLabels.$inferSelect;
export type IssueLabel = typeof sqlLiteIssueLabels.$inferSelect;
export const githubStarsModel = pgGithubStars;
export type UserInsert = typeof sqlLiteUsers.$inferInsert;
export type PullRequestInsert = typeof sqlLitePullRequests.$inferInsert;
export type IssueInsert = typeof sqlLiteIssues.$inferInsert;
export type LabelInsert = typeof sqlLiteLabels.$inferInsert;
export type PullRequestLabelInsert =
typeof sqlLitePullRequestLabels.$inferInsert;
export type IssueLabelInsert = typeof sqlLiteIssueLabels.$inferInsert;
export type User = typeof pgUsers.$inferSelect;
export type PullRequest = typeof pgPullRequests.$inferSelect;
export type Issue = typeof pgIssues.$inferSelect;
export type Label = typeof pgLabels.$inferSelect;
export type PullRequestLabel = typeof pgPullRequestLabels.$inferSelect;
export type IssueLabel = typeof pgIssueLabels.$inferSelect;
export type UserInsert = typeof pgUsers.$inferInsert;
export type PullRequestInsert = typeof pgPullRequests.$inferInsert;
export type IssueInsert = typeof pgIssues.$inferInsert;
export type LabelInsert = typeof pgLabels.$inferInsert;
export type PullRequestLabelInsert = typeof pgPullRequestLabels.$inferInsert;
export type IssueLabelInsert = typeof pgIssueLabels.$inferInsert;
export type GithubStars = typeof pgGithubStars.$inferInsert;

View File

@ -81,4 +81,4 @@ DO $$ BEGIN
ALTER TABLE "pullRequests" ADD CONSTRAINT "pullRequests_authorId_users_id_fk" FOREIGN KEY ("authorId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
END $$;

View File

@ -0,0 +1,4 @@
CREATE TABLE IF NOT EXISTS "githubStars" (
"timestamp" timestamp DEFAULT now() NOT NULL,
"numberOfStars" integer
);

View File

@ -27,12 +27,8 @@
"name": "issueLabels_issueId_issues_id_fk",
"tableFrom": "issueLabels",
"tableTo": "issues",
"columnsFrom": [
"issueId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["issueId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
@ -40,12 +36,8 @@
"name": "issueLabels_labelId_labels_id_fk",
"tableFrom": "issueLabels",
"tableTo": "labels",
"columnsFrom": [
"labelId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["labelId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
@ -118,12 +110,8 @@
"name": "issues_authorId_users_id_fk",
"tableFrom": "issues",
"tableTo": "users",
"columnsFrom": [
"authorId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["authorId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
@ -194,12 +182,8 @@
"name": "pullRequestLabels_pullRequestExternalId_pullRequests_id_fk",
"tableFrom": "pullRequestLabels",
"tableTo": "pullRequests",
"columnsFrom": [
"pullRequestExternalId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["pullRequestExternalId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
@ -207,12 +191,8 @@
"name": "pullRequestLabels_labelId_labels_id_fk",
"tableFrom": "pullRequestLabels",
"tableTo": "labels",
"columnsFrom": [
"labelId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["labelId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
@ -285,12 +265,8 @@
"name": "pullRequests_authorId_users_id_fk",
"tableFrom": "pullRequests",
"tableTo": "users",
"columnsFrom": [
"authorId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["authorId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
@ -340,4 +316,4 @@
"schemas": {},
"tables": {}
}
}
}

View File

@ -8,6 +8,13 @@
"when": 1707921820164,
"tag": "0000_absent_giant_man",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1713792223113,
"tag": "0001_marvelous_eddie_brock",
"breakpoints": true
}
]
}

View File

@ -1,4 +1,4 @@
import { pgTable, text } from 'drizzle-orm/pg-core';
import { integer, pgTable, text, timestamp } from 'drizzle-orm/pg-core';
export const pgUsers = pgTable('users', {
id: text('id').primaryKey(),
@ -50,3 +50,8 @@ export const pgIssueLabels = pgTable('issueLabels', {
issueId: text('issueId').references(() => pgIssues.id),
labelId: text('labelId').references(() => pgLabels.id),
});
export const pgGithubStars = pgTable('githubStars', {
timestamp: timestamp('timestamp').notNull().defaultNow(),
numberOfStars: integer('numberOfStars'),
});

View File

@ -10,4 +10,4 @@
"breakpoints": true
}
]
}
}