first commit

This commit is contained in:
mstfyldz
2026-03-24 15:46:27 +03:00
parent 095d830279
commit 34b6a46604
33 changed files with 5212 additions and 81 deletions

12
db/index.ts Normal file
View File

@@ -0,0 +1,12 @@
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as schema from "./schema";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env.local" });
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
export const db = drizzle(pool, { schema });

47
db/schema/index.ts Normal file
View File

@@ -0,0 +1,47 @@
import { pgTable, serial, text, timestamp, varchar, jsonb, integer, boolean } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
password: text("password").notNull(),
role: varchar("role", { length: 20 }).default("user").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// Uygulamalar Tablosu
export const apps = pgTable("apps", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 100 }).notNull(),
bundleId: varchar("bundle_id", { length: 100 }).notNull().unique(),
appleId: varchar("apple_id", { length: 100 }), // App Store Connect için
platform: varchar("platform", { length: 20 }).default("ios").notNull(), // ios, android, dual
status: varchar("status", { length: 50 }).default("active").notNull(),
iconUrl: text("icon_url"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Remote Config & App Settings
export const remoteConfig = pgTable("remote_config", {
id: serial("id").primaryKey(),
appId: integer("app_id").references(() => apps.id, { onDelete: 'cascade' }).notNull(),
configKey: varchar("config_key", { length: 100 }).notNull(),
configValue: jsonb("config_value").notNull(),
description: text("description"),
isActive: boolean("is_active").default(true).notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
// Mevcut items tablosunu "Global İçerik" olarak saklayabiliriz veya genişletebiliriz.
export const items = pgTable("items", {
id: serial("id").primaryKey(),
appId: integer("app_id").references(() => apps.id, { onDelete: 'cascade' }), // Hangi uygulamaya ait?
key: varchar("key", { length: 100 }).notNull(),
title: text("title").notNull(),
content: text("content"),
data: jsonb("data"),
type: varchar("type", { length: 50 }).default("generic").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});

25
db/seed.ts Normal file
View File

@@ -0,0 +1,25 @@
import { db } from "./index";
import { users } from "./schema";
import bcrypt from "bcryptjs";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env.local" });
async function seed() {
const hashedPassword = await bcrypt.hash("admin123", 10);
await db.insert(users).values({
name: "Admin",
email: "admin@admin.com",
password: hashedPassword,
role: "admin",
}).onConflictDoNothing();
console.log("Admin user created.");
process.exit(0);
}
seed().catch(err => {
console.error(err);
process.exit(1);
});

21
db/test-conn.ts Normal file
View File

@@ -0,0 +1,21 @@
import { Client } from 'pg';
import * as dotenv from 'dotenv';
dotenv.config({ path: '.env.local' });
async function test() {
const client = new Client({
connectionString: process.env.DATABASE_URL,
});
try {
await client.connect();
console.log("Connected successfully");
const res = await client.query('SELECT NOW()');
console.log(res.rows[0]);
await client.end();
} catch (err) {
console.error("Connection error", err);
}
}
test();