mirror of
https://github.com/khairul169/github-leaderboard.git
synced 2026-09-17 09:53:21 +07:00
feat: migrate db to postgres
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
import { InferInsertModel, InferSelectModel, relations } from "drizzle-orm";
|
||||
import {
|
||||
text,
|
||||
sqliteTable,
|
||||
varchar,
|
||||
serial,
|
||||
pgTable,
|
||||
integer,
|
||||
index,
|
||||
real,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
doublePrecision,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { repositories } from "./repositories";
|
||||
|
||||
export const repoLanguages = sqliteTable(
|
||||
export const repoLanguages = pgTable(
|
||||
"repository_languages",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
id: serial("id").primaryKey(),
|
||||
repoId: integer("repo_id")
|
||||
.notNull()
|
||||
.references(() => repositories.id),
|
||||
|
||||
name: text("name").notNull(),
|
||||
percentage: real("percentage").notNull(),
|
||||
name: varchar("name").notNull(),
|
||||
percentage: doublePrecision("percentage").notNull(),
|
||||
},
|
||||
(t) => ({
|
||||
nameIdx: index("repository_languages_name_idx").on(t.name),
|
||||
|
||||
@@ -5,37 +5,44 @@ import {
|
||||
relations,
|
||||
sql,
|
||||
} from "drizzle-orm";
|
||||
import { text, sqliteTable, integer, index } from "drizzle-orm/sqlite-core";
|
||||
import {
|
||||
varchar,
|
||||
pgTable,
|
||||
integer,
|
||||
index,
|
||||
serial,
|
||||
jsonb,
|
||||
boolean,
|
||||
timestamp,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { users } from "./users";
|
||||
import { repoLanguages } from "./repo-languages";
|
||||
|
||||
export const repositories = sqliteTable(
|
||||
export const repositories = pgTable(
|
||||
"repositories",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
id: serial("id").primaryKey(),
|
||||
userId: integer("user_id")
|
||||
.notNull()
|
||||
.references(() => users.id),
|
||||
|
||||
name: text("name").notNull(),
|
||||
uri: text("uri").notNull(),
|
||||
language: text("language").notNull(),
|
||||
name: varchar("name").notNull(),
|
||||
uri: varchar("uri").notNull(),
|
||||
language: varchar("language").notNull(),
|
||||
stars: integer("stars").notNull(),
|
||||
forks: integer("forks").notNull(),
|
||||
lastUpdate: text("last_update").notNull(),
|
||||
contributors: text("contributors", { mode: "json" }).$type<Contributor[]>(),
|
||||
lastUpdate: varchar("last_update").notNull(),
|
||||
contributors: jsonb("contributors").$type<Contributor[]>(),
|
||||
|
||||
isPending: integer("is_pending", { mode: "boolean" })
|
||||
.notNull()
|
||||
.default(false),
|
||||
isError: integer("is_error", { mode: "boolean" }).notNull().default(false),
|
||||
isPending: boolean("is_pending").notNull().default(false),
|
||||
isError: boolean("is_error").notNull().default(false),
|
||||
|
||||
createdAt: text("created_at")
|
||||
createdAt: timestamp("created_at")
|
||||
.notNull()
|
||||
.default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: text("updated_at")
|
||||
updatedAt: timestamp("updated_at")
|
||||
.notNull()
|
||||
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
||||
.$onUpdate(() => new Date()),
|
||||
},
|
||||
(t) => ({
|
||||
nameIdx: index("repositories_name_idx").on(t.name),
|
||||
|
||||
+19
-14
@@ -1,30 +1,35 @@
|
||||
import { Achievement } from "@server/lib/github";
|
||||
import { InferInsertModel, InferSelectModel, sql } from "drizzle-orm";
|
||||
import { text, sqliteTable, integer } from "drizzle-orm/sqlite-core";
|
||||
import {
|
||||
varchar,
|
||||
pgTable,
|
||||
serial,
|
||||
integer,
|
||||
jsonb,
|
||||
timestamp,
|
||||
} from "drizzle-orm/pg-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"),
|
||||
export const users = pgTable("users", {
|
||||
id: serial("id").primaryKey(),
|
||||
username: varchar("username").notNull().unique(),
|
||||
name: varchar("name").notNull(),
|
||||
avatar: varchar("avatar"),
|
||||
location: varchar("location"),
|
||||
followers: integer("followers").notNull().default(0),
|
||||
following: integer("following").notNull().default(0),
|
||||
achievements: text("achievements", { mode: "json" })
|
||||
.$type<Achievement[]>()
|
||||
.default([]),
|
||||
achievements: jsonb("achievements").$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"),
|
||||
accessToken: varchar("access_token"),
|
||||
|
||||
createdAt: text("created_at")
|
||||
createdAt: timestamp("created_at")
|
||||
.notNull()
|
||||
.default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: text("updated_at")
|
||||
updatedAt: timestamp("updated_at")
|
||||
.notNull()
|
||||
.$onUpdate(() => sql`CURRENT_TIMESTAMP`),
|
||||
.$onUpdate(() => new Date()),
|
||||
});
|
||||
|
||||
export type User = InferSelectModel<typeof users>;
|
||||
|
||||
Reference in New Issue
Block a user