Merge branch 'testing' into testing2

This commit is contained in:
aronmal 2023-07-24 00:27:53 +02:00
commit 5eb03189f1
Signed by: aronmal
GPG key ID: 816B7707426FC612
6 changed files with 5175 additions and 1804 deletions

View file

@ -0,0 +1,11 @@
import "dotenv/config"
import type { Config } from "drizzle-kit"
export default {
schema: "./drizzle/schema.ts",
out: "./drizzle/migrations",
driver: "pg",
dbCredentials: {
connectionString: process.env.DATABASE_URL ?? "",
},
} satisfies Config

View file

@ -0,0 +1,7 @@
import { drizzle, PostgresJsDatabase } from "drizzle-orm/postgres-js"
import postgres from "postgres"
const queryClient = postgres(process.env.DATABASE_URL ?? "")
const db: PostgresJsDatabase = drizzle(queryClient)
export default db

View file

@ -0,0 +1,131 @@
import { createId } from "@paralleldrive/cuid2"
import { relations } from "drizzle-orm"
import {
boolean,
integer,
pgTable,
text,
timestamp,
type AnyPgColumn,
} from "drizzle-orm/pg-core"
export const users = pgTable("users", {
id: text("id").primaryKey().notNull(),
})
export const games = pgTable("Game", {
id: text("id").primaryKey().default(createId()),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
state: text("state").default("lobby"),
allowSpectators: boolean("allow_spectators").default(true),
allowSpecials: boolean("allow_specials").default(true),
allowChat: boolean("allow_chat").default(true),
allowMarkDraw: boolean("allow_mark_draw").default(true),
gamePinId: text("game_pin_id").references((): AnyPgColumn => gamepins.id),
})
export const gamepins = pgTable("Gamepin", {
id: text("id").primaryKey().default(createId()),
createdAt: timestamp("created_at").notNull().defaultNow(),
pin: text("pin"),
gameId: text("game_id").references((): AnyPgColumn => games.id),
})
export const ships = pgTable("Ship", {
id: text("id").primaryKey().default(createId()),
size: integer("size"),
variant: integer("variant"),
x: integer("x"),
y: integer("y"),
orientation: text("orientation"),
user_GameId: text("user_game_id").references(() => user_games.id),
})
export const hits = pgTable("Hit", {
id: text("id").primaryKey().default(createId()),
x: integer("x"),
y: integer("y"),
hit: boolean("hit"),
user_GameId: text("user_game_id").references(() => user_games.id),
})
export const user_games = pgTable("User_Game", {
id: text("id").primaryKey().default(createId()),
createdAt: timestamp("created_at").notNull().defaultNow(),
gameId: text("game_id").references(() => games.id),
userId: text("user_id").references(() => users.id),
index: integer("index"),
})
export const moves = pgTable("Move", {
id: text("id").primaryKey().default(createId()),
createdAt: timestamp("created_at").notNull().defaultNow(),
index: integer("index"),
type: text("type"),
x: integer("x"),
y: integer("y"),
orientation: text("orientation"),
user_game_id: text("user_game_id").references(() => user_games.id),
})
export const chats = pgTable("Chat", {
id: text("id").primaryKey().default(createId()),
createdAt: timestamp("created_at").notNull().defaultNow(),
message: text("message"),
event: text("event"),
user_game_id: text("user_game_id").references(() => user_games.id),
})
export const usersRelations = relations(users, ({ many }) => ({
games: many(user_games),
}))
export const gamesRelations = relations(games, ({ one, many }) => ({
gamePin: one(gamepins, {
fields: [games.gamePinId],
references: [gamepins.id],
}),
users: many(user_games),
}))
export const gamepinsRelations = relations(gamepins, ({ one }) => ({
game: one(games, { fields: [gamepins.gameId], references: [games.id] }),
}))
export const shipsRelations = relations(ships, ({ one }) => ({
userGame: one(user_games, {
fields: [ships.user_GameId],
references: [user_games.id],
}),
}))
export const hitsRelations = relations(hits, ({ one }) => ({
userGame: one(user_games, {
fields: [hits.user_GameId],
references: [user_games.id],
}),
}))
export const userGamesRelations = relations(user_games, ({ one, many }) => ({
user: one(users, { fields: [user_games.userId], references: [users.id] }),
game: one(games, { fields: [user_games.gameId], references: [games.id] }),
moves: many(moves),
ships: many(ships),
hits: many(hits),
chats: many(chats),
}))
export const movesRelations = relations(moves, ({ one }) => ({
userGame: one(user_games, {
fields: [moves.user_game_id],
references: [user_games.id],
}),
}))
export const chatsRelations = relations(chats, ({ one }) => ({
userGame: one(user_games, {
fields: [chats.user_game_id],
references: [user_games.id],
}),
}))

View file

@ -21,16 +21,19 @@
"@fortawesome/sharp-solid-svg-icons": "^6.4.0",
"@next-auth/prisma-adapter": "^1.0.7",
"@next/font": "13.1.1",
"@paralleldrive/cuid2": "^2.2.1",
"@prisma/client": "^4.16.2",
"classnames": "^2.3.2",
"colors": "^1.4.0",
"drizzle-orm": "^0.27.2",
"eslint": "8.31.0",
"eslint-config-next": "13.1.1",
"http-status": "^1.6.2",
"immer": "^10.0.2",
"next": "13.1.1",
"next-auth": "^4.22.3",
"nodemailer": "^6.9.4",
"next-auth": "^4.22.1",
"nodemailer": "^6.9.3",
"postgres": "^3.3.5",
"prisma": "^4.16.2",
"react": "18.2.0",
"react-colorful": "^5.6.1",
@ -47,19 +50,22 @@
},
"devDependencies": {
"@total-typescript/ts-reset": "^0.3.7",
"@types/node": "^18.17.0",
"@types/node": "^18.16.19",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@types/web-bluetooth": "^0.0.16",
"autoprefixer": "^10.4.14",
"dotenv": "^16.3.1",
"drizzle-kit": "^0.19.5",
"eslint-config-prettier": "^8.8.0",
"jest": "^29.6.1",
"jest-puppeteer": "^9.0.0",
"postcss": "^8.4.27",
"pg": "^8.11.1",
"postcss": "^8.4.26",
"prettier": "^3.0.0",
"prettier-plugin-organize-imports": "^3.2.3",
"prettier-plugin-tailwindcss": "^0.4.1",
"sass": "^1.64.1",
"prettier-plugin-tailwindcss": "^0.4.0",
"sass": "^1.63.6",
"tailwindcss": "^3.3.3"
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,