[db] change field case
This commit is contained in:
@@ -13,8 +13,7 @@ const connectionConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString:
|
connectionString: process.env.DATABASE_URL ?? process.env.DATABASE_PRIMARY_URL!,
|
||||||
process.env.DATABASE_URL ?? process.env.DATABASE_PRIMARY_URL!,
|
|
||||||
...connectionConfig,
|
...connectionConfig,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -31,9 +30,7 @@ export const getConnectionPoolStats = () => {
|
|||||||
|
|
||||||
const totalConnections = connectionConfig.max;
|
const totalConnections = connectionConfig.max;
|
||||||
const utilization =
|
const utilization =
|
||||||
totalConnections > 0
|
totalConnections > 0 ? Math.round((stats.active / totalConnections) * 100) : 0;
|
||||||
? Math.round((stats.active / totalConnections) * 100)
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
@@ -44,8 +41,7 @@ export const getConnectionPoolStats = () => {
|
|||||||
totalConnections,
|
totalConnections,
|
||||||
totalActive: stats.active,
|
totalActive: stats.active,
|
||||||
totalWaiting: stats.waiting,
|
totalWaiting: stats.waiting,
|
||||||
hasExhaustedPools:
|
hasExhaustedPools: stats.active >= totalConnections || (stats.waiting ?? 0) > 0,
|
||||||
stats.active >= totalConnections || (stats.waiting ?? 0) > 0,
|
|
||||||
utilizationPercent: utilization,
|
utilizationPercent: utilization,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,14 +2,7 @@ import type { AnyColumn, SQL } from "drizzle-orm";
|
|||||||
import { and, asc, desc, eq, gt, lt, or, sql } from "drizzle-orm";
|
import { and, asc, desc, eq, gt, lt, or, sql } from "drizzle-orm";
|
||||||
|
|
||||||
import type { Database } from "@/client";
|
import type { Database } from "@/client";
|
||||||
import {
|
import { articles, bookmarkArticles, bookmarks, comments, sources, users } from "@/schema";
|
||||||
articles,
|
|
||||||
bookmarkArticles,
|
|
||||||
bookmarks,
|
|
||||||
comments,
|
|
||||||
sources,
|
|
||||||
users,
|
|
||||||
} from "@/schema";
|
|
||||||
import {
|
import {
|
||||||
buildPaginationResult,
|
buildPaginationResult,
|
||||||
createPageState,
|
createPageState,
|
||||||
@@ -117,8 +110,7 @@ export async function* getArticlesForExport(
|
|||||||
db: Database,
|
db: Database,
|
||||||
params: ArticleExportParams = {},
|
params: ArticleExportParams = {},
|
||||||
): AsyncGenerator<ArticleExportRow> {
|
): AsyncGenerator<ArticleExportRow> {
|
||||||
const batchSize =
|
const batchSize = params.batchSize && params.batchSize > 0 ? params.batchSize : 1000;
|
||||||
params.batchSize && params.batchSize > 0 ? params.batchSize : 1000;
|
|
||||||
|
|
||||||
const filters: SQL[] = [];
|
const filters: SQL[] = [];
|
||||||
|
|
||||||
@@ -183,19 +175,13 @@ export async function* getArticlesForExport(
|
|||||||
|
|
||||||
const SOURCE_IMAGE_BASE = "https://devscast.org/images/sources/";
|
const SOURCE_IMAGE_BASE = "https://devscast.org/images/sources/";
|
||||||
|
|
||||||
function normalizeArticleFilters(
|
function normalizeArticleFilters(filters?: ArticleFilters): NormalizedArticleFilters {
|
||||||
filters?: ArticleFilters,
|
|
||||||
): NormalizedArticleFilters {
|
|
||||||
const trimmedSearch = filters?.search?.trim();
|
const trimmedSearch = filters?.search?.trim();
|
||||||
const trimmedCategory = filters?.category?.trim();
|
const trimmedCategory = filters?.category?.trim();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
search:
|
search: trimmedSearch && trimmedSearch.length > 0 ? trimmedSearch : undefined,
|
||||||
trimmedSearch && trimmedSearch.length > 0 ? trimmedSearch : undefined,
|
category: trimmedCategory && trimmedCategory.length > 0 ? trimmedCategory : undefined,
|
||||||
category:
|
|
||||||
trimmedCategory && trimmedCategory.length > 0
|
|
||||||
? trimmedCategory
|
|
||||||
: undefined,
|
|
||||||
dateRange: filters?.dateRange ?? null,
|
dateRange: filters?.dateRange ?? null,
|
||||||
sortDirection: filters?.sortDirection ?? "desc",
|
sortDirection: filters?.sortDirection ?? "desc",
|
||||||
};
|
};
|
||||||
@@ -261,8 +247,9 @@ async function fetchArticleOverview(
|
|||||||
},
|
},
|
||||||
): Promise<ArticleOverviewResult> {
|
): Promise<ArticleOverviewResult> {
|
||||||
const baseConditions = options.baseConditions ?? [];
|
const baseConditions = options.baseConditions ?? [];
|
||||||
const { conditions: filterConditions, searchQuery } =
|
const { conditions: filterConditions, searchQuery } = buildArticleFilterConditions(
|
||||||
buildArticleFilterConditions(options.filters);
|
options.filters,
|
||||||
|
);
|
||||||
const whereConditions = [...baseConditions, ...filterConditions];
|
const whereConditions = [...baseConditions, ...filterConditions];
|
||||||
|
|
||||||
const bookmarkExpression = buildBookmarkExistsExpression(options.userId);
|
const bookmarkExpression = buildBookmarkExistsExpression(options.userId);
|
||||||
@@ -297,17 +284,11 @@ async function fetchArticleOverview(
|
|||||||
options.filters.sortDirection === "asc"
|
options.filters.sortDirection === "asc"
|
||||||
? or(
|
? or(
|
||||||
gt(articles.publishedAt, cursor.date),
|
gt(articles.publishedAt, cursor.date),
|
||||||
and(
|
and(eq(articles.publishedAt, cursor.date), gt(articles.id, cursor.id)),
|
||||||
eq(articles.publishedAt, cursor.date),
|
|
||||||
gt(articles.id, cursor.id),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: or(
|
: or(
|
||||||
lt(articles.publishedAt, cursor.date),
|
lt(articles.publishedAt, cursor.date),
|
||||||
and(
|
and(eq(articles.publishedAt, cursor.date), lt(articles.id, cursor.id)),
|
||||||
eq(articles.publishedAt, cursor.date),
|
|
||||||
lt(articles.id, cursor.id),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
whereConditions.push(comparison);
|
whereConditions.push(comparison);
|
||||||
}
|
}
|
||||||
@@ -394,8 +375,7 @@ export async function getBookmarkedArticleList(
|
|||||||
): Promise<ArticleOverviewResult> {
|
): Promise<ArticleOverviewResult> {
|
||||||
const page = createPageState(params.page);
|
const page = createPageState(params.page);
|
||||||
const filters = normalizeArticleFilters(params.filters);
|
const filters = normalizeArticleFilters(params.filters);
|
||||||
const { conditions: filterConditions, searchQuery } =
|
const { conditions: filterConditions, searchQuery } = buildArticleFilterConditions(filters);
|
||||||
buildArticleFilterConditions(filters);
|
|
||||||
|
|
||||||
const whereConditions: SQL[] = [
|
const whereConditions: SQL[] = [
|
||||||
eq(bookmarks.id, params.bookmarkId),
|
eq(bookmarks.id, params.bookmarkId),
|
||||||
@@ -435,17 +415,11 @@ export async function getBookmarkedArticleList(
|
|||||||
filters.sortDirection === "asc"
|
filters.sortDirection === "asc"
|
||||||
? or(
|
? or(
|
||||||
gt(articles.publishedAt, cursor.date),
|
gt(articles.publishedAt, cursor.date),
|
||||||
and(
|
and(eq(articles.publishedAt, cursor.date), gt(articles.id, cursor.id)),
|
||||||
eq(articles.publishedAt, cursor.date),
|
|
||||||
gt(articles.id, cursor.id),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: or(
|
: or(
|
||||||
lt(articles.publishedAt, cursor.date),
|
lt(articles.publishedAt, cursor.date),
|
||||||
and(
|
and(eq(articles.publishedAt, cursor.date), lt(articles.id, cursor.id)),
|
||||||
eq(articles.publishedAt, cursor.date),
|
|
||||||
lt(articles.id, cursor.id),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
whereConditions.push(comparison);
|
whereConditions.push(comparison);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ export interface SourceStatisticsRow {
|
|||||||
articleMetadataAvailable: number;
|
articleMetadataAvailable: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSourceStatisticsList(
|
export async function getSourceStatisticsList(db: Database): Promise<SourceStatisticsRow[]> {
|
||||||
db: Database,
|
|
||||||
): Promise<SourceStatisticsRow[]> {
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.select({
|
.select({
|
||||||
sourceId: sources.id,
|
sourceId: sources.id,
|
||||||
@@ -111,8 +109,7 @@ async function selectPublicationBoundary(
|
|||||||
conditions.push(sql`${params.category} = ANY(${articles.categories})`);
|
conditions.push(sql`${params.category} = ANY(${articles.categories})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const whereClause =
|
const whereClause = conditions.length > 1 ? and(...conditions) : conditions[0];
|
||||||
conditions.length > 1 ? and(...conditions) : conditions[0];
|
|
||||||
|
|
||||||
const [result] = await db
|
const [result] = await db
|
||||||
.select({
|
.select({
|
||||||
@@ -181,9 +178,7 @@ export async function getSourceOverviewList(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const rows = await query
|
const rows = await query.orderBy(desc(sources.createdAt), desc(sources.id)).limit(page.limit + 1);
|
||||||
.orderBy(desc(sources.createdAt), desc(sources.id))
|
|
||||||
.limit(page.limit + 1);
|
|
||||||
|
|
||||||
return buildPaginationResult(rows, page, {
|
return buildPaginationResult(rows, page, {
|
||||||
id: "sourceId",
|
id: "sourceId",
|
||||||
@@ -200,10 +195,7 @@ function createBackwardDateRange(days: number): { start: number; end: number } {
|
|||||||
return { start, end };
|
return { start, end };
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchPublicationGraph(
|
async function fetchPublicationGraph(db: Database, sourceId: string): Promise<PublicationEntry[]> {
|
||||||
db: Database,
|
|
||||||
sourceId: string,
|
|
||||||
): Promise<PublicationEntry[]> {
|
|
||||||
const range = createBackwardDateRange(PUBLICATION_GRAPH_DAYS);
|
const range = createBackwardDateRange(PUBLICATION_GRAPH_DAYS);
|
||||||
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
@@ -239,11 +231,7 @@ async function fetchPublicationGraph(
|
|||||||
const start = new Date(range.start * 1000);
|
const start = new Date(range.start * 1000);
|
||||||
const end = new Date(range.end * 1000);
|
const end = new Date(range.end * 1000);
|
||||||
|
|
||||||
for (
|
for (let date = new Date(start.getTime()); date < end; date.setUTCDate(date.getUTCDate() + 1)) {
|
||||||
let date = new Date(start.getTime());
|
|
||||||
date < end;
|
|
||||||
date.setUTCDate(date.getUTCDate() + 1)
|
|
||||||
) {
|
|
||||||
const day = date.toISOString().slice(0, 10);
|
const day = date.toISOString().slice(0, 10);
|
||||||
entries.push({ day, count: counts.get(day) ?? 0 });
|
entries.push({ day, count: counts.get(day) ?? 0 });
|
||||||
}
|
}
|
||||||
@@ -251,10 +239,7 @@ async function fetchPublicationGraph(
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchCategoryShares(
|
async function fetchCategoryShares(db: Database, sourceId: string): Promise<CategoryShare[]> {
|
||||||
db: Database,
|
|
||||||
sourceId: string,
|
|
||||||
): Promise<CategoryShare[]> {
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.select({
|
.select({
|
||||||
categories: sql<string | null>`array_to_string
|
categories: sql<string | null>`array_to_string
|
||||||
@@ -273,18 +258,13 @@ async function fetchCategoryShares(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const total = Array.from(counts.values()).reduce(
|
const total = Array.from(counts.values()).reduce((acc, value) => acc + value, 0);
|
||||||
(acc, value) => acc + value,
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
const shares: CategoryShare[] = Array.from(counts.entries()).map(
|
const shares: CategoryShare[] = Array.from(counts.entries()).map(([category, count]) => ({
|
||||||
([category, count]) => ({
|
category,
|
||||||
category,
|
count,
|
||||||
count,
|
percentage: total > 0 ? Math.round((count / total) * 10000) / 100 : 0,
|
||||||
percentage: total > 0 ? Math.round((count / total) * 10000) / 100 : 0,
|
}));
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
shares.sort((a, b) => b.count - a.count);
|
shares.sort((a, b) => b.count - a.count);
|
||||||
return shares;
|
return shares;
|
||||||
|
|||||||
@@ -53,12 +53,7 @@ export const articleSentimentEnum = pgEnum("article_sentiment", [
|
|||||||
"negative",
|
"negative",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const biasEnum = pgEnum("bias", [
|
export const biasEnum = pgEnum("bias", ["neutral", "slightly", "partisan", "extreme"]);
|
||||||
"neutral",
|
|
||||||
"slightly",
|
|
||||||
"partisan",
|
|
||||||
"extreme",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const reliabilityEnum = pgEnum("reliability", [
|
export const reliabilityEnum = pgEnum("reliability", [
|
||||||
"trusted",
|
"trusted",
|
||||||
@@ -68,16 +63,14 @@ export const reliabilityEnum = pgEnum("reliability", [
|
|||||||
"unreliable",
|
"unreliable",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const transparencyEnum = pgEnum("transparency", [
|
export const transparencyEnum = pgEnum("transparency", ["high", "medium", "low"]);
|
||||||
"high",
|
|
||||||
"medium",
|
|
||||||
"low",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const verificationTokenPurposeEnum = pgEnum(
|
export const verificationTokenPurposeEnum = pgEnum("verification_token_purpose", [
|
||||||
"verification_token_purpose",
|
"confirm_account",
|
||||||
["confirm_account", "password_reset", "unlock_account", "delete_account"],
|
"password_reset",
|
||||||
);
|
"unlock_account",
|
||||||
|
"delete_account",
|
||||||
|
]);
|
||||||
|
|
||||||
export const sources = pgTable(
|
export const sources = pgTable(
|
||||||
"source",
|
"source",
|
||||||
@@ -87,9 +80,7 @@ export const sources = pgTable(
|
|||||||
name: varchar("name", { length: 255 }).notNull(),
|
name: varchar("name", { length: 255 }).notNull(),
|
||||||
displayName: varchar("display_name", { length: 255 }),
|
displayName: varchar("display_name", { length: 255 }),
|
||||||
description: varchar("description", { length: 1024 }),
|
description: varchar("description", { length: 1024 }),
|
||||||
createdAt: timestamp("created_at", { mode: "string" })
|
createdAt: timestamp("created_at", { mode: "string" }).defaultNow().notNull(),
|
||||||
.defaultNow()
|
|
||||||
.notNull(),
|
|
||||||
updatedAt: timestamp("updated_at", { mode: "string" }),
|
updatedAt: timestamp("updated_at", { mode: "string" }),
|
||||||
bias: biasEnum("bias").notNull().default("neutral"),
|
bias: biasEnum("bias").notNull().default("neutral"),
|
||||||
reliability: reliabilityEnum("reliability").notNull().default("reliable"),
|
reliability: reliabilityEnum("reliability").notNull().default("reliable"),
|
||||||
@@ -121,9 +112,7 @@ export const articles = pgTable(
|
|||||||
sentiment: articleSentimentEnum("sentiment").notNull().default("neutral"),
|
sentiment: articleSentimentEnum("sentiment").notNull().default("neutral"),
|
||||||
metadata: jsonb("metadata"),
|
metadata: jsonb("metadata"),
|
||||||
tokenStatistics: jsonb("token_statistics"),
|
tokenStatistics: jsonb("token_statistics"),
|
||||||
image: varchar("image", { length: 1024 }).generatedAlwaysAs(
|
image: varchar("image", { length: 1024 }).generatedAlwaysAs(() => sql`(metadata->>'image')`),
|
||||||
() => sql`(metadata->>'image')`,
|
|
||||||
),
|
|
||||||
excerpt: varchar("excerpt", { length: 255 }).generatedAlwaysAs(
|
excerpt: varchar("excerpt", { length: 255 }).generatedAlwaysAs(
|
||||||
() => sql`((left(body, 200) || '...'))`,
|
() => sql`((left(body, 200) || '...'))`,
|
||||||
),
|
),
|
||||||
@@ -145,18 +134,11 @@ export const articles = pgTable(
|
|||||||
(table) => [
|
(table) => [
|
||||||
index("article_sourceId_idx").on(table.sourceId),
|
index("article_sourceId_idx").on(table.sourceId),
|
||||||
index("idx_article_published_at").using("btree", table.publishedAt.desc()),
|
index("idx_article_published_at").using("btree", table.publishedAt.desc()),
|
||||||
index("idx_article_published_id").using(
|
index("idx_article_published_id").using("btree", table.publishedAt.desc(), table.id.desc()),
|
||||||
"btree",
|
|
||||||
table.publishedAt.desc(),
|
|
||||||
table.id.desc(),
|
|
||||||
),
|
|
||||||
unique("unq_article_hash").on(table.hash),
|
unique("unq_article_hash").on(table.hash),
|
||||||
index("gin_article_tsv").using("gin", table.tsv),
|
index("gin_article_tsv").using("gin", table.tsv),
|
||||||
index("gin_articleLink_trgm").using("gin", table.link.op("gin_trgm_ops")),
|
index("gin_articleLink_trgm").using("gin", table.link.op("gin_trgm_ops")),
|
||||||
index("gin_articleTitle_trgm").using(
|
index("gin_articleTitle_trgm").using("gin", table.title.op("gin_trgm_ops")),
|
||||||
"gin",
|
|
||||||
table.title.op("gin_trgm_ops"),
|
|
||||||
),
|
|
||||||
index("gin_articleCategories").using("gin", table.categories),
|
index("gin_articleCategories").using("gin", table.categories),
|
||||||
foreignKey({
|
foreignKey({
|
||||||
columns: [table.sourceId],
|
columns: [table.sourceId],
|
||||||
@@ -212,11 +194,7 @@ export const bookmarks = pgTable(
|
|||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
index("bookmark_user_id_idx").on(table.userId),
|
index("bookmark_user_id_idx").on(table.userId),
|
||||||
index("idx_bookmark_user_created").using(
|
index("idx_bookmark_user_created").using("btree", table.userId, table.createdAt.desc()),
|
||||||
"btree",
|
|
||||||
table.userId,
|
|
||||||
table.createdAt.desc(),
|
|
||||||
),
|
|
||||||
foreignKey({
|
foreignKey({
|
||||||
columns: [table.userId],
|
columns: [table.userId],
|
||||||
foreignColumns: [users.id],
|
foreignColumns: [users.id],
|
||||||
@@ -265,11 +243,7 @@ export const comments = pgTable(
|
|||||||
(table) => [
|
(table) => [
|
||||||
index("comment_user_id_idx").on(table.userId),
|
index("comment_user_id_idx").on(table.userId),
|
||||||
index("comment_article_id_idx").on(table.articleId),
|
index("comment_article_id_idx").on(table.articleId),
|
||||||
index("idx_comment_article_created").using(
|
index("idx_comment_article_created").using("btree", table.articleId, table.createdAt.desc()),
|
||||||
"btree",
|
|
||||||
table.articleId,
|
|
||||||
table.createdAt.desc(),
|
|
||||||
),
|
|
||||||
foreignKey({
|
foreignKey({
|
||||||
columns: [table.userId],
|
columns: [table.userId],
|
||||||
foreignColumns: [users.id],
|
foreignColumns: [users.id],
|
||||||
@@ -321,10 +295,7 @@ export const loginAttempts = pgTable(
|
|||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
index("login_attempt_user_id_idx").on(table.userId),
|
index("login_attempt_user_id_idx").on(table.userId),
|
||||||
index("idx_login_attempt_created_at").using(
|
index("idx_login_attempt_created_at").using("btree", table.createdAt.desc()),
|
||||||
"btree",
|
|
||||||
table.createdAt.desc(),
|
|
||||||
),
|
|
||||||
foreignKey({
|
foreignKey({
|
||||||
columns: [table.userId],
|
columns: [table.userId],
|
||||||
foreignColumns: [users.id],
|
foreignColumns: [users.id],
|
||||||
@@ -351,11 +322,7 @@ export const loginHistories = pgTable(
|
|||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
index("login_history_user_id_idx").on(table.userId),
|
index("login_history_user_id_idx").on(table.userId),
|
||||||
index("idx_login_history_created_at").using(
|
index("idx_login_history_created_at").using("btree", table.userId, table.createdAt.desc()),
|
||||||
"btree",
|
|
||||||
table.userId,
|
|
||||||
table.createdAt.desc(),
|
|
||||||
),
|
|
||||||
index("login_history_ip_address_idx").on(table.ipAddress),
|
index("login_history_ip_address_idx").on(table.ipAddress),
|
||||||
foreignKey({
|
foreignKey({
|
||||||
columns: [table.userId],
|
columns: [table.userId],
|
||||||
@@ -368,9 +335,7 @@ export const loginHistories = pgTable(
|
|||||||
export const refreshTokens = pgTable(
|
export const refreshTokens = pgTable(
|
||||||
"refresh_tokens",
|
"refresh_tokens",
|
||||||
{
|
{
|
||||||
id: integer("id")
|
id: integer("id").generatedAlwaysAsIdentity({ name: "refresh_tokens_id_seq" }).primaryKey(),
|
||||||
.generatedAlwaysAsIdentity({ name: "refresh_tokens_id_seq" })
|
|
||||||
.primaryKey(),
|
|
||||||
refreshToken: varchar("refresh_token", { length: 128 }).notNull(),
|
refreshToken: varchar("refresh_token", { length: 128 }).notNull(),
|
||||||
username: varchar("username", { length: 255 }).notNull(),
|
username: varchar("username", { length: 255 }).notNull(),
|
||||||
validUntil: timestamp("valid", { mode: "string" }).notNull(),
|
validUntil: timestamp("valid", { mode: "string" }).notNull(),
|
||||||
@@ -389,10 +354,7 @@ export const verificationTokens = pgTable(
|
|||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
index("verification_token_user_id_idx").on(table.userId),
|
index("verification_token_user_id_idx").on(table.userId),
|
||||||
index("idx_verification_token_created_at").using(
|
index("idx_verification_token_created_at").using("btree", table.createdAt.desc()),
|
||||||
"btree",
|
|
||||||
table.createdAt.desc(),
|
|
||||||
),
|
|
||||||
uniqueIndex("unq_verification_token_user_purpose")
|
uniqueIndex("unq_verification_token_user_purpose")
|
||||||
.on(table.userId, table.purpose)
|
.on(table.userId, table.purpose)
|
||||||
.where(sql`token IS NOT NULL`),
|
.where(sql`token IS NOT NULL`),
|
||||||
@@ -437,19 +399,16 @@ export const bookmarksRelations = relations(bookmarks, ({ one, many }) => ({
|
|||||||
articles: many(bookmarkArticles),
|
articles: many(bookmarkArticles),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const bookmarkArticlesRelations = relations(
|
export const bookmarkArticlesRelations = relations(bookmarkArticles, ({ one }) => ({
|
||||||
bookmarkArticles,
|
bookmark: one(bookmarks, {
|
||||||
({ one }) => ({
|
fields: [bookmarkArticles.bookmarkId],
|
||||||
bookmark: one(bookmarks, {
|
references: [bookmarks.id],
|
||||||
fields: [bookmarkArticles.bookmarkId],
|
|
||||||
references: [bookmarks.id],
|
|
||||||
}),
|
|
||||||
article: one(articles, {
|
|
||||||
fields: [bookmarkArticles.articleId],
|
|
||||||
references: [articles.id],
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
);
|
article: one(articles, {
|
||||||
|
fields: [bookmarkArticles.articleId],
|
||||||
|
references: [articles.id],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
export const commentsRelations = relations(comments, ({ one }) => ({
|
export const commentsRelations = relations(comments, ({ one }) => ({
|
||||||
article: one(articles, {
|
article: one(articles, {
|
||||||
@@ -462,19 +421,16 @@ export const commentsRelations = relations(comments, ({ one }) => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const followedSourcesRelations = relations(
|
export const followedSourcesRelations = relations(followedSources, ({ one }) => ({
|
||||||
followedSources,
|
follower: one(users, {
|
||||||
({ one }) => ({
|
fields: [followedSources.followerId],
|
||||||
follower: one(users, {
|
references: [users.id],
|
||||||
fields: [followedSources.followerId],
|
|
||||||
references: [users.id],
|
|
||||||
}),
|
|
||||||
source: one(sources, {
|
|
||||||
fields: [followedSources.sourceId],
|
|
||||||
references: [sources.id],
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
);
|
source: one(sources, {
|
||||||
|
fields: [followedSources.sourceId],
|
||||||
|
references: [sources.id],
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
export const loginAttemptsRelations = relations(loginAttempts, ({ one }) => ({
|
export const loginAttemptsRelations = relations(loginAttempts, ({ one }) => ({
|
||||||
user: one(users, {
|
user: one(users, {
|
||||||
@@ -490,12 +446,9 @@ export const loginHistoriesRelations = relations(loginHistories, ({ one }) => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const verificationTokensRelations = relations(
|
export const verificationTokensRelations = relations(verificationTokens, ({ one }) => ({
|
||||||
verificationTokens,
|
user: one(users, {
|
||||||
({ one }) => ({
|
fields: [verificationTokens.userId],
|
||||||
user: one(users, {
|
references: [users.id],
|
||||||
fields: [verificationTokens.userId],
|
|
||||||
references: [users.id],
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
);
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user