mirror of
https://github.com/khairul169/github-leaderboard.git
synced 2026-09-17 09:53:21 +07:00
feat: initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export { users } from "./users";
|
||||
export { repositories } from "./repositories";
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Contributor, Language } from "@server/lib/github";
|
||||
import { InferInsertModel, InferSelectModel, sql } from "drizzle-orm";
|
||||
import { text, sqliteTable, integer, index } from "drizzle-orm/sqlite-core";
|
||||
import { users } from "./users";
|
||||
|
||||
export const repositories = sqliteTable(
|
||||
"repositories",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
userId: integer("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
|
||||
name: text("name").notNull(),
|
||||
uri: text("uri").notNull(),
|
||||
language: text("language").notNull(),
|
||||
stars: integer("stars").notNull(),
|
||||
forks: integer("stars").notNull(),
|
||||
lastUpdate: text("last_update").notNull(),
|
||||
languages: text("languages", { mode: "json" }).$type<Language[]>(),
|
||||
contributors: text("contributors", { mode: "json" }).$type<Contributor[]>(),
|
||||
|
||||
createdAt: text("created_at")
|
||||
.notNull()
|
||||
.default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: text("updated_at")
|
||||
.notNull()
|
||||
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
||||
},
|
||||
(t) => ({
|
||||
nameIdx: index("repositories_name_idx").on(t.name),
|
||||
uriIdx: index("repositories_uri_idx").on(t.uri),
|
||||
language: index("repositories_language_idx").on(t.language),
|
||||
})
|
||||
);
|
||||
|
||||
export type Repository = InferSelectModel<typeof repositories>;
|
||||
export type CreateRepository = InferInsertModel<typeof repositories>;
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Achievement } from "@server/lib/github";
|
||||
import { InferInsertModel, InferSelectModel, sql } from "drizzle-orm";
|
||||
import { text, sqliteTable, integer } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const users = sqliteTable("users", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
username: text("username").notNull().unique(),
|
||||
name: text("name").notNull(),
|
||||
avatar: text("avatar"),
|
||||
location: text("location"),
|
||||
followers: integer("followers").notNull().default(0),
|
||||
following: integer("following").notNull().default(0),
|
||||
achievements: text("achievements", { mode: "json" })
|
||||
.$type<Achievement[]>()
|
||||
.default([]),
|
||||
points: integer("points").notNull().default(0),
|
||||
commits: integer("commits").notNull().default(0),
|
||||
lineOfCodes: integer("line_of_codes").notNull().default(0),
|
||||
githubId: integer("github_id").unique(),
|
||||
accessToken: text("access_token"),
|
||||
|
||||
createdAt: text("created_at")
|
||||
.notNull()
|
||||
.default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: text("updated_at")
|
||||
.notNull()
|
||||
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
||||
});
|
||||
|
||||
export type User = InferSelectModel<typeof users>;
|
||||
export type CreateUser = InferInsertModel<typeof users>;
|
||||
Reference in New Issue
Block a user