Skip to content

Commit

Permalink
wagmi
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Mar 21, 2024
1 parent 006d36f commit 6bed840
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 133 deletions.
24 changes: 18 additions & 6 deletions src/scripts/seed/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { Scrypt } from "lucia"
import "dotenv/config"
import * as dotenv from "dotenv"
import { generateID } from "@/v2/lib/oslo"

dotenv.config({ path: ".dev.vars" })

Expand Down Expand Up @@ -254,15 +255,21 @@ async function main() {
)

console.log("[SEED] [asset] Seeding assets...")

const assetIDArray = new Array(6).fill(null).map(() => {
return generateID()
})

const newAssets = await db
.insert(asset)
.values([
{
id: assetIDArray[0],
name: "test-asset",
extension: "image/png",
gameId: "genshin-impact",
assetCategoryId: "character-sheets",
url: "/genshin-impact/character-sheets/test-asset.png",
url: `/assets/${assetIDArray[0]}.png`,
status: "approved",
uploadedById: newUsers[0].id,
uploadedByName: newUsers[0].username,
Expand All @@ -273,11 +280,12 @@ async function main() {
height: 512,
},
{
id: assetIDArray[1],
name: "test-asset-2",
extension: "image/png",
gameId: "honkai-impact-3rd",
assetCategoryId: "character-sheets",
url: "/honkai-impact-3rd/character-sheets/test-asset2.png",
url: `/assets/${assetIDArray[1]}.png`,
status: "approved",
uploadedById: newUsers[1].id,
uploadedByName: newUsers[1].username,
Expand All @@ -288,11 +296,12 @@ async function main() {
height: 1080,
},
{
id: assetIDArray[2],
name: "test-asset-3",
extension: "image/png",
gameId: "genshin-impact",
assetCategoryId: "splash-art",
url: "/genshin-impact/splash-art/test-asset3.png",
url: `/assets/${assetIDArray[2]}.png`,
status: "approved",
uploadedById: newUsers[1].id,
uploadedByName: newUsers[1].username,
Expand All @@ -303,11 +312,12 @@ async function main() {
height: 1920,
},
{
id: assetIDArray[3],
name: "test-asset-4",
extension: "image/png",
gameId: "genshin-impact",
assetCategoryId: "splash-art",
url: "/genshin-impact/splash-art/test-asset4.png",
url: `/assets/${assetIDArray[3]}.png`,
status: "approved",
uploadedById: newUsers[1].id,
uploadedByName: newUsers[1].username,
Expand All @@ -318,23 +328,25 @@ async function main() {
height: 1080,
},
{
id: assetIDArray[4],
name: "test-asset-5",
extension: "image/png",
gameId: "genshin-impact",
assetCategoryId: "splash-art",
url: "/genshin-impact/splash-art/test-asset5.png",
url: `/assets/${assetIDArray[4]}.png`,
status: "approved",
uploadedById: newUsers[2].id,
uploadedByName: newUsers[2].username,
viewCount: 1337,
downloadCount: 1337,
},
{
id: assetIDArray[5],
name: "test-asset-6",
extension: "image/png",
gameId: "honkai-impact-3rd",
assetCategoryId: "character-sheets",
url: "/honkai-impact-3rd/character-sheets/test-asset6.png",
url: `/assets/${assetIDArray[5]}.png`,
status: "approved",
uploadedById: newUsers[2].id,
uploadedByName: newUsers[2].username,
Expand Down
6 changes: 3 additions & 3 deletions src/v2/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export * from "./schema/asset/asset-external-files"
export * from "./schema/asset/asset-likes"

export * from "./schema/categories/asset-categories"
export * from "./schema/categories/asset-categories-likes"
// export * from "./schema/categories/asset-categories-likes"

export * from "./schema/game/game"
export * from "./schema/game/game-likes"
// export * from "./schema/game/game-likes"

export * from "./schema/tags/asset-tags"
export * from "./schema/tags/asset-tags-likes"
// export * from "./schema/tags/asset-tags-likes"

export * from "./schema/user/user"
export * from "./schema/user/user-attributes"
Expand Down
2 changes: 1 addition & 1 deletion src/v2/db/schema/asset/asset-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const assetComments = sqliteTable(
.primaryKey()
.notNull()
.$defaultFn(() => {
return generateID()
return generateID(20)
}),
assetId: text("asset_id").references(() => asset.id, {
onUpdate: "cascade",
Expand Down
4 changes: 2 additions & 2 deletions src/v2/db/schema/asset/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const asset = sqliteTable(
.primaryKey()
.notNull()
.$defaultFn(() => {
return generateID()
return generateID(15)
}),
name: text("name").notNull(),
extension: text("extension").notNull(),
Expand Down Expand Up @@ -78,7 +78,7 @@ export const asset = sqliteTable(
.default(false)
.notNull(),
allowComments: integer("comments_is_locked", { mode: "boolean" })
.default(true)
.default(false)
.notNull(),
viewCount: integer("view_count").default(0).notNull(),
downloadCount: integer("download_count").default(0).notNull(),
Expand Down
118 changes: 59 additions & 59 deletions src/v2/db/schema/categories/asset-categories-likes.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import { tableNames } from "@/v2/db/drizzle"
import { relations } from "drizzle-orm"
import { index, sqliteTable, text } from "drizzle-orm/sqlite-core"
import { authUser } from "../user/user"
import { createInsertSchema, createSelectSchema } from "drizzle-zod"
import { assetCategory } from "./asset-categories"
// import { tableNames } from "@/v2/db/drizzle"
// import { relations } from "drizzle-orm"
// import { index, sqliteTable, text } from "drizzle-orm/sqlite-core"
// import { authUser } from "../user/user"
// import { createInsertSchema, createSelectSchema } from "drizzle-zod"
// import { assetCategory } from "./asset-categories"

export const assetCategoryLikes = sqliteTable(
tableNames.assetCategoryLikes,
{
assetCategoryId: text("asset_id")
.notNull()
.references(() => assetCategory.id, {
onUpdate: "cascade",
onDelete: "cascade",
}),
likedById: text("liked_by_id")
.notNull()
.references(() => authUser.id, {
onUpdate: "cascade",
onDelete: "cascade",
}),
createdAt: text("created_at")
.notNull()
.$defaultFn(() => {
return new Date().toISOString()
}),
},
(gameLikes) => {
return {
assetCategoryIdx: index("assetCategoryLikes_asset_idx").on(
gameLikes.assetCategoryId
),
likedByIdx: index("assetCategoryLikes_likedby_idx").on(
gameLikes.likedById
),
}
}
)
// export const assetCategoryLikes = sqliteTable(
// tableNames.assetCategoryLikes,
// {
// assetCategoryId: text("asset_id")
// .notNull()
// .references(() => assetCategory.id, {
// onUpdate: "cascade",
// onDelete: "cascade",
// }),
// likedById: text("liked_by_id")
// .notNull()
// .references(() => authUser.id, {
// onUpdate: "cascade",
// onDelete: "cascade",
// }),
// createdAt: text("created_at")
// .notNull()
// .$defaultFn(() => {
// return new Date().toISOString()
// }),
// },
// (gameLikes) => {
// return {
// assetCategoryIdx: index("assetCategoryLikes_asset_idx").on(
// gameLikes.assetCategoryId
// ),
// likedByIdx: index("assetCategoryLikes_likedby_idx").on(
// gameLikes.likedById
// ),
// }
// }
// )

export type AssetCategoryLikes = typeof assetCategoryLikes.$inferSelect
export type NewAssetCategoryLikes = typeof assetCategoryLikes.$inferInsert
export const insertAssetCategoryLikesSchema =
createInsertSchema(assetCategoryLikes)
export const selectAssetCategoryLikesSchema =
createSelectSchema(assetCategoryLikes)
// export type AssetCategoryLikes = typeof assetCategoryLikes.$inferSelect
// export type NewAssetCategoryLikes = typeof assetCategoryLikes.$inferInsert
// export const insertAssetCategoryLikesSchema =
// createInsertSchema(assetCategoryLikes)
// export const selectAssetCategoryLikesSchema =
// createSelectSchema(assetCategoryLikes)

export const assetCategoryLikesRelations = relations(
assetCategoryLikes,
({ one }) => ({
assetCategory: one(assetCategory, {
fields: [assetCategoryLikes.assetCategoryId],
references: [assetCategory.id],
relationName: "assetCategoryLikes_liked_assetCategory",
}),
likedBy: one(authUser, {
fields: [assetCategoryLikes.likedById],
references: [authUser.id],
relationName: "assetTagLikes_liked_by",
}),
})
)
// export const assetCategoryLikesRelations = relations(
// assetCategoryLikes,
// ({ one }) => ({
// assetCategory: one(assetCategory, {
// fields: [assetCategoryLikes.assetCategoryId],
// references: [assetCategory.id],
// relationName: "assetCategoryLikes_liked_assetCategory",
// }),
// likedBy: one(authUser, {
// fields: [assetCategoryLikes.likedById],
// references: [authUser.id],
// relationName: "assetTagLikes_liked_by",
// }),
// })
// )
4 changes: 2 additions & 2 deletions src/v2/db/schema/categories/asset-categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { game } from "../game/game"
import { asset } from "../asset/asset"
import { createInsertSchema, createSelectSchema } from "drizzle-zod"
import { assetCategoryLikes } from "./asset-categories-likes"
// import { assetCategoryLikes } from "./asset-categories-likes"

export const assetCategory = sqliteTable(
tableNames.assetCategory,
Expand Down Expand Up @@ -78,7 +78,7 @@ export const selectGameAssetCategorySchema =
export const assetCategoryRelations = relations(assetCategory, ({ many }) => ({
asset: many(asset),
gameAssetCategory: many(gameAssetCategory),
assetCategoryLikes: many(assetCategoryLikes),
// assetCategoryLikes: many(assetCategoryLikes),
}))

export const gameAssetCategoryRelations = relations(
Expand Down
100 changes: 50 additions & 50 deletions src/v2/db/schema/game/game-likes.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import { tableNames } from "@/v2/db/drizzle"
import { relations } from "drizzle-orm"
import { index, sqliteTable, text } from "drizzle-orm/sqlite-core"
import { authUser } from "../user/user"
import { game } from "./game"
import { createInsertSchema, createSelectSchema } from "drizzle-zod"
// import { tableNames } from "@/v2/db/drizzle"
// import { relations } from "drizzle-orm"
// import { index, sqliteTable, text } from "drizzle-orm/sqlite-core"
// import { authUser } from "../user/user"
// import { game } from "./game"
// import { createInsertSchema, createSelectSchema } from "drizzle-zod"

export const gameLikes = sqliteTable(
tableNames.gameLikes,
{
gameId: text("asset_id")
.notNull()
.references(() => game.id, {
onUpdate: "cascade",
onDelete: "cascade",
}),
likedById: text("liked_by_id")
.notNull()
.references(() => authUser.id, {
onUpdate: "cascade",
onDelete: "cascade",
}),
createdAt: text("created_at")
.notNull()
.$defaultFn(() => {
return new Date().toISOString()
}),
},
(gameLikes) => {
return {
gameIdx: index("gamelikes_game_idx").on(gameLikes.gameId),
likedByIdx: index("gamelikes_likedby_idx").on(gameLikes.likedById),
}
}
)
// export const gameLikes = sqliteTable(
// tableNames.gameLikes,
// {
// gameId: text("asset_id")
// .notNull()
// .references(() => game.id, {
// onUpdate: "cascade",
// onDelete: "cascade",
// }),
// likedById: text("liked_by_id")
// .notNull()
// .references(() => authUser.id, {
// onUpdate: "cascade",
// onDelete: "cascade",
// }),
// createdAt: text("created_at")
// .notNull()
// .$defaultFn(() => {
// return new Date().toISOString()
// }),
// },
// (gameLikes) => {
// return {
// gameIdx: index("gamelikes_game_idx").on(gameLikes.gameId),
// likedByIdx: index("gamelikes_likedby_idx").on(gameLikes.likedById),
// }
// }
// )

export type GameLikes = typeof gameLikes.$inferSelect
export type NewGameLikes = typeof gameLikes.$inferInsert
export const insertGameLikesSchema = createInsertSchema(gameLikes)
export const selectGameLikesSchema = createSelectSchema(gameLikes)
// export type GameLikes = typeof gameLikes.$inferSelect
// export type NewGameLikes = typeof gameLikes.$inferInsert
// export const insertGameLikesSchema = createInsertSchema(gameLikes)
// export const selectGameLikesSchema = createSelectSchema(gameLikes)

export const gameLikesRelations = relations(gameLikes, ({ one }) => ({
game: one(game, {
fields: [gameLikes.gameId],
references: [game.id],
relationName: "gamelikes_liked_game",
}),
likedBy: one(authUser, {
fields: [gameLikes.likedById],
references: [authUser.id],
relationName: "gamelikes_liked_by",
}),
}))
// export const gameLikesRelations = relations(gameLikes, ({ one }) => ({
// game: one(game, {
// fields: [gameLikes.gameId],
// references: [game.id],
// relationName: "gamelikes_liked_game",
// }),
// likedBy: one(authUser, {
// fields: [gameLikes.likedById],
// references: [authUser.id],
// relationName: "gamelikes_liked_by",
// }),
// }))
Loading

0 comments on commit 6bed840

Please sign in to comment.