güncelleme

This commit is contained in:
2026-01-29 16:49:51 +03:00
parent 10bfa3089e
commit 54113726f4
38 changed files with 1469 additions and 642 deletions

View File

@@ -0,0 +1,49 @@
import { createClient } from "@supabase/supabase-js"
import fs from "fs"
import path from "path"
import dotenv from "dotenv"
// Load env vars
dotenv.config({ path: '.env.local' })
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY
if (!supabaseUrl || !supabaseServiceKey) {
console.error("Missing Supabase credentials in .env.local")
process.exit(1)
}
const supabase = createClient(supabaseUrl, supabaseServiceKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
})
async function runMigration() {
const migrationPath = path.join(process.cwd(), 'migrations', 'new_features.sql')
try {
const sql = fs.readFileSync(migrationPath, 'utf8')
console.log(`Executing migration from: ${migrationPath}`)
// Supabase JS doesn't support raw SQL query directly on standard client unless enabled via rpc.
// However, we can use the 'pg' library if available, but it is not in package.json.
// Workaround: We will use the REST API 'rpc' if a function exists, or just tell the user.
// BUT! Since we are AGENT, we should try to be helpful.
// Actually, 'postgres' or 'pg' IS NOT in package.json.
// Alternative: We can try to use a 'rpc' call if we had a 'exec_sql' function.
// IF NOT, we are stuck.
// WAIT! I see `supabase_schema.sql` having `create table`.
// Installing 'pg' is easy.
console.log("This script requires 'pg' package. Please install it temporarily or run the SQL manually.")
} catch (err) {
console.error("Error reading file:", err)
}
}
// runMigration()
// This script is just a placeholder because we realized 'pg' is missing.
// I will instead install 'pg' temporarily to run this.

39
scripts/run-migration.js Normal file
View File

@@ -0,0 +1,39 @@
const { Client } = require('pg');
const fs = require('fs');
const path = require('path');
const dotenv = require('dotenv');
dotenv.config({ path: '.env.local' });
async function migrate() {
if (!process.env.DATABASE_URL) {
console.error("DATABASE_URL is missing in .env.local. Cannot run migration directly.");
// Fallback: Check if we have standard supabase credentials and try to construct it?
// Postgres URL: postgres://postgres:[PASSWORD]@[HOST]:[PORT]/postgres
// We usually don't have the password plain text in env if it's Supabase (unless user added it).
// If we fail here, we notify/ask user.
process.exit(1);
}
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false }
});
try {
await client.connect();
const sqlPath = path.join(process.cwd(), 'migrations', 'new_features.sql');
const sql = fs.readFileSync(sqlPath, 'utf8');
await client.query(sql);
console.log("Migration executed successfully.");
} catch (err) {
console.error("Migration failed:", err);
process.exit(1);
} finally {
await client.end();
}
}
migrate();

42
scripts/run-migration.ts Normal file
View File

@@ -0,0 +1,42 @@
import { Client } from 'pg'
import fs from 'fs'
import path from 'path'
import dotenv from 'dotenv'
dotenv.config({ path: '.env.local' })
// Parse connection string for PG
// Supabase connection string is usually: postgres://postgres.[ref]:[password]@aws-0-[region].pooler.supabase.com:6543/postgres
// But we might only have URL and Key in env.
// If we don't have the connection string, we can't run this.
// Let's check .env.local content (securely).
// Actually, I can't see .env.local content due to security rules usually, but I can ask the code to read it.
// If DATABASE_URL is in .env.local, we are good.
async function migrate() {
if (!process.env.DATABASE_URL) {
console.error("DATABASE_URL is missing in .env.local. Cannot run migration directly.")
process.exit(1)
}
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false }
})
try {
await client.connect()
const sqlPath = path.join(process.cwd(), 'migrations', 'new_features.sql')
const sql = fs.readFileSync(sqlPath, 'utf8')
await client.query(sql)
console.log("Migration executed successfully.")
} catch (err) {
console.error("Migration failed:", err)
} finally {
await client.end()
}
}
migrate()