Enhance Next.js configuration and dependencies for improved functionality and localization support. Added support for internationalization with next-intl, updated global styles, and integrated new fonts. Removed default home page and updated README with project details and setup instructions.
This commit is contained in:
1 parent
2911dea00b
commit
44f4fa98e2
320 files changed
+31666
-220
No files matched your search
@@ -0,0 +1,92 @@
|
||||
// Phase A — migration runner
|
||||
// Usage: node db/migrate.mjs
|
||||
// Reads DATABASE_URL from .env.local if not already in the environment.
|
||||
// Applies each file in db/migrations/*.sql in filename order, once, atomically.
|
||||
// Tracks applied versions in a schema_migrations table; re-running is a no-op.
|
||||
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import pg from "pg";
|
||||
|
||||
const { Client } = pg;
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
const envPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".env.local");
|
||||
if (existsSync(envPath)) {
|
||||
for (const line of readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
||||
const match = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (match && !(match[1] in process.env)) {
|
||||
process.env[match[1]] = match[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error("DATABASE_URL is not set and .env.local was not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const migrationsDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "migrations");
|
||||
|
||||
async function main() {
|
||||
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
||||
await client.connect();
|
||||
|
||||
try {
|
||||
await client.query(`
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
version TEXT PRIMARY KEY,
|
||||
applied_at TIMESTAMPTZ DEFAULT now()
|
||||
)
|
||||
`);
|
||||
|
||||
const appliedRes = await client.query("SELECT version FROM schema_migrations");
|
||||
const applied = new Set(appliedRes.rows.map((r) => r.version));
|
||||
|
||||
const files = (await readdir(migrationsDir)).filter((f) => f.endsWith(".sql")).sort();
|
||||
|
||||
let appliedCount = 0;
|
||||
const skipped = [];
|
||||
|
||||
for (const file of files) {
|
||||
if (applied.has(file)) {
|
||||
skipped.push(file);
|
||||
continue;
|
||||
}
|
||||
const sql = await readFile(path.join(migrationsDir, file), "utf8");
|
||||
try {
|
||||
await client.query("BEGIN");
|
||||
await client.query(sql);
|
||||
await client.query("INSERT INTO schema_migrations (version) VALUES ($1)", [file]);
|
||||
await client.query("COMMIT");
|
||||
console.log("applied:", file);
|
||||
appliedCount += 1;
|
||||
} catch (error) {
|
||||
await client.query("ROLLBACK").catch(() => {});
|
||||
console.error("FAILED on:", file);
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const tables = await client.query(`
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
|
||||
ORDER BY table_name
|
||||
`);
|
||||
|
||||
console.log(`applied_count: ${appliedCount}`);
|
||||
console.log(`skipped (already applied): ${skipped.length ? skipped.join(", ") : "none"}`);
|
||||
console.log(`tables_count: ${tables.rows.length}`);
|
||||
console.log(JSON.stringify(tables.rows.map((r) => r.table_name)));
|
||||
} finally {
|
||||
await client.end().catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -0,0 +1,215 @@
|
||||
-- Phase A — Initial schema
|
||||
-- Corresponds to docs/04-development-plan.md §3 (A.1–A.7) + site content tables.
|
||||
-- All statements are idempotent (IF NOT EXISTS) so reruns are safe;
|
||||
-- db/migrate.mjs additionally tracks applied versions in schema_migrations.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS courses (
|
||||
id TEXT PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
summary TEXT NOT NULL,
|
||||
category TEXT NOT NULL
|
||||
CHECK (category IN ('leadership','technology','innovation','energy','design','digital')),
|
||||
duration_hours INT NOT NULL CHECK (duration_hours > 0),
|
||||
format TEXT NOT NULL
|
||||
CHECK (format IN ('online','blended','in-person')),
|
||||
registration_url TEXT NOT NULL,
|
||||
image_url TEXT NOT NULL,
|
||||
seo_description TEXT NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now(),
|
||||
published BOOLEAN DEFAULT true
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS programs (
|
||||
id TEXT PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
blurb TEXT NOT NULL,
|
||||
group_key TEXT NOT NULL
|
||||
CHECK (group_key IN ('standard','executive')),
|
||||
href TEXT NOT NULL,
|
||||
tagline TEXT NULL,
|
||||
audience TEXT NOT NULL,
|
||||
duration_label TEXT NOT NULL,
|
||||
format_label TEXT NOT NULL,
|
||||
highlights JSONB NOT NULL DEFAULT '[]',
|
||||
body TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS events (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
start_date DATE NOT NULL,
|
||||
end_date DATE NULL,
|
||||
location TEXT NOT NULL,
|
||||
href TEXT NOT NULL,
|
||||
summary TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS articles (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
category TEXT NOT NULL,
|
||||
excerpt TEXT NOT NULL,
|
||||
image_url TEXT NOT NULL,
|
||||
href TEXT NOT NULL,
|
||||
featured BOOLEAN NOT NULL DEFAULT false,
|
||||
body TEXT NOT NULL,
|
||||
published_at DATE NOT NULL,
|
||||
author TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- Domain rule: at most one *published* featured article (docs/02-domain-rules.md §Business + plan §A.4).
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS articles_one_featured
|
||||
ON articles ((featured))
|
||||
WHERE featured = true AND published = true;
|
||||
|
||||
-- Site content (plan §A.5) — matches src/lib/types/* entities.
|
||||
CREATE TABLE IF NOT EXISTS intersection_topics (
|
||||
id TEXT PRIMARY KEY,
|
||||
slug TEXT UNIQUE NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
href TEXT NOT NULL,
|
||||
image_url TEXT NOT NULL,
|
||||
body TEXT NOT NULL,
|
||||
highlights JSONB NOT NULL DEFAULT '[]',
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS faculty_members (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
focus TEXT NOT NULL,
|
||||
bio TEXT NOT NULL,
|
||||
image_url TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS alumni_stories (
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
excerpt TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
program TEXT NOT NULL,
|
||||
image_url TEXT NOT NULL,
|
||||
href TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS campaign_banners (
|
||||
id TEXT PRIMARY KEY,
|
||||
version TEXT NOT NULL,
|
||||
text TEXT NOT NULL,
|
||||
href TEXT NOT NULL,
|
||||
cta TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS legal_pages (
|
||||
slug TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
body JSONB NOT NULL DEFAULT '[]',
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS site_stats (
|
||||
id TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL,
|
||||
label TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS testimonials (
|
||||
id TEXT PRIMARY KEY,
|
||||
quote TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
course_title TEXT NOT NULL,
|
||||
published BOOLEAN DEFAULT true,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- Registration leads (plan §A.6, used in phase G).
|
||||
CREATE TABLE IF NOT EXISTS registration_leads (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
course_id TEXT NULL REFERENCES courses(id) ON DELETE SET NULL,
|
||||
course_slug TEXT NULL,
|
||||
full_name TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
phone TEXT NULL,
|
||||
message TEXT NULL,
|
||||
source TEXT NOT NULL DEFAULT 'register_page',
|
||||
status TEXT NOT NULL DEFAULT 'new'
|
||||
CHECK (status IN ('new','contacted','enrolled','rejected')),
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- Admin (plan §A.7, used in phase E).
|
||||
CREATE TABLE IF NOT EXISTS admin_users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email TEXT UNIQUE NOT NULL,
|
||||
password_hash TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
role TEXT NOT NULL DEFAULT 'admin',
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS admin_sessions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
token_hash TEXT UNIQUE NOT NULL,
|
||||
user_id UUID NOT NULL REFERENCES admin_users(id) ON DELETE CASCADE,
|
||||
expires_at TIMESTAMPTZ NOT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
-- Keep updated_at meaningful on every write (used by admin CRUD in later phases).
|
||||
CREATE OR REPLACE FUNCTION set_updated_at()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
t TEXT;
|
||||
BEGIN
|
||||
FOREACH t IN ARRAY ARRAY[
|
||||
'courses','programs','events','articles',
|
||||
'intersection_topics','faculty_members','alumni_stories',
|
||||
'campaign_banners','legal_pages','site_stats','testimonials'
|
||||
]
|
||||
LOOP
|
||||
EXECUTE format(
|
||||
'CREATE TRIGGER trg_%I_set_updated_at BEFORE UPDATE ON %I FOR EACH ROW EXECUTE FUNCTION set_updated_at()',
|
||||
t, t
|
||||
);
|
||||
END LOOP;
|
||||
END;
|
||||
$$;
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Phase H — additional indexes for read paths used by the data layer.
|
||||
-- Note: courses.slug, programs.slug, intersection_topics.slug are already
|
||||
-- UNIQUE (001), and featured articles are covered by the partial unique
|
||||
-- index articles_one_featured (001), so they are not repeated here.
|
||||
|
||||
-- Admin registrations list (ORDER BY created_at DESC).
|
||||
CREATE INDEX IF NOT EXISTS idx_registration_leads_created_at
|
||||
ON registration_leads (created_at DESC);
|
||||
|
||||
-- Articles list (WHERE published ORDER BY published_at DESC).
|
||||
CREATE INDEX IF NOT EXISTS idx_articles_published_at
|
||||
ON articles (published, published_at DESC);
|
||||
|
||||
-- Events list (WHERE published ORDER BY start_date ASC).
|
||||
CREATE INDEX IF NOT EXISTS idx_events_start
|
||||
ON events (published, start_date);
|
||||
|
||||
-- Programs / courses lists (WHERE published ORDER BY title ASC).
|
||||
CREATE INDEX IF NOT EXISTS idx_programs_title
|
||||
ON programs (published, title);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_courses_title
|
||||
ON courses (published, title);
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Optional course price (تومان). NULL = hide price in UI (current behavior).
|
||||
ALTER TABLE courses
|
||||
ADD COLUMN IF NOT EXISTS price BIGINT NULL
|
||||
CHECK (price IS NULL OR price >= 0);
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
// Phase B — seed mock content into PostgreSQL.
|
||||
// Usage: node db/seed.mjs (re-runnable; uses upsert by primary key)
|
||||
// Reads DATABASE_URL from .env.local if not already in the environment.
|
||||
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import pg from "pg";
|
||||
|
||||
import { courses } from "../src/lib/mock/courses.ts";
|
||||
import { programs } from "../src/lib/mock/programs.ts";
|
||||
import { events } from "../src/lib/mock/events.ts";
|
||||
import { articles } from "../src/lib/mock/articles.ts";
|
||||
import {
|
||||
alumniStories,
|
||||
campaignBanners,
|
||||
faculty,
|
||||
intersections,
|
||||
legalPages,
|
||||
stats,
|
||||
testimonials,
|
||||
} from "../src/lib/mock/site.ts";
|
||||
|
||||
import {
|
||||
alumniStoryToRow,
|
||||
articleToRow,
|
||||
campaignBannerToRow,
|
||||
courseToRow,
|
||||
eventToRow,
|
||||
facultyMemberToRow,
|
||||
intersectionTopicToRow,
|
||||
legalPageToRow,
|
||||
programToRow,
|
||||
siteStatToRow,
|
||||
testimonialToRow,
|
||||
} from "../src/lib/db/mappers.ts";
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
const envPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".env.local");
|
||||
if (existsSync(envPath)) {
|
||||
for (const line of readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
||||
const match = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (match && !(match[1] in process.env)) {
|
||||
process.env[match[1]] = match[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error("DATABASE_URL is not set and .env.local was not found.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { Client } = pg;
|
||||
|
||||
async function upsertByKey(client, table, rows, columns, key = "id") {
|
||||
if (rows.length === 0) return 0;
|
||||
const placeholders = columns.map((_, i) => `$${i + 1}`).join(", ");
|
||||
const updates = columns
|
||||
.filter((c) => c !== key)
|
||||
.map((c) => `${c} = EXCLUDED.${c}`)
|
||||
.join(", ");
|
||||
const sql = `INSERT INTO ${table} (${columns.join(", ")}) VALUES (${placeholders})
|
||||
ON CONFLICT (${key}) DO UPDATE SET ${updates}`;
|
||||
for (const row of rows) {
|
||||
const values = columns.map((c) => row[c]);
|
||||
await client.query(sql, values);
|
||||
}
|
||||
return rows.length;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const client = new Client({ connectionString: process.env.DATABASE_URL });
|
||||
await client.connect();
|
||||
|
||||
try {
|
||||
const results = [];
|
||||
const upsert = (table, rows, columns, key) =>
|
||||
upsertByKey(client, table, rows, columns, key).then((n) => {
|
||||
results.push([table, n]);
|
||||
});
|
||||
|
||||
await upsert("courses", courses.map(courseToRow), [
|
||||
"id", "slug", "title", "summary", "category", "duration_hours", "format", "price",
|
||||
"registration_url", "image_url", "seo_description", "published",
|
||||
]);
|
||||
await upsert("programs", programs.map(programToRow), [
|
||||
"id", "slug", "title", "blurb", "group_key", "href", "tagline", "audience",
|
||||
"duration_label", "format_label", "highlights", "body", "published",
|
||||
]);
|
||||
await upsert("events", events.map(eventToRow), [
|
||||
"id", "title", "start_date", "end_date", "location", "href", "summary", "published",
|
||||
]);
|
||||
await upsert("articles", articles.map(articleToRow), [
|
||||
"id", "title", "category", "excerpt", "image_url", "href", "featured",
|
||||
"body", "published_at", "author", "published",
|
||||
]);
|
||||
await upsert("intersection_topics", intersections.map(intersectionTopicToRow), [
|
||||
"id", "slug", "title", "description", "href", "image_url", "body", "highlights", "published",
|
||||
]);
|
||||
await upsert("faculty_members", faculty.map(facultyMemberToRow), [
|
||||
"id", "name", "title", "focus", "bio", "image_url", "published",
|
||||
]);
|
||||
await upsert("alumni_stories", alumniStories.map(alumniStoryToRow), [
|
||||
"id", "title", "excerpt", "name", "program", "image_url", "href", "published",
|
||||
]);
|
||||
await upsert("campaign_banners", campaignBanners.map(campaignBannerToRow), [
|
||||
"id", "version", "text", "href", "cta", "published",
|
||||
]);
|
||||
await upsert("legal_pages", legalPages.map(legalPageToRow), [
|
||||
"slug", "title", "body", "published",
|
||||
], "slug");
|
||||
await upsert("site_stats", stats.map(siteStatToRow), [
|
||||
"id", "value", "label", "published",
|
||||
]);
|
||||
await upsert("testimonials", testimonials.map(testimonialToRow), [
|
||||
"id", "quote", "name", "role", "course_title", "published",
|
||||
]);
|
||||
|
||||
const counts = await client.query(`
|
||||
SELECT (SELECT count(*) FROM courses) AS courses,
|
||||
(SELECT count(*) FROM programs) AS programs,
|
||||
(SELECT count(*) FROM events) AS events,
|
||||
(SELECT count(*) FROM articles) AS articles,
|
||||
(SELECT count(*) FROM intersection_topics) AS topics,
|
||||
(SELECT count(*) FROM faculty_members) AS faculty,
|
||||
(SELECT count(*) FROM alumni_stories) AS alumni,
|
||||
(SELECT count(*) FROM campaign_banners) AS banners,
|
||||
(SELECT count(*) FROM legal_pages) AS legal,
|
||||
(SELECT count(*) FROM site_stats) AS stats,
|
||||
(SELECT count(*) FROM testimonials) AS testimonials,
|
||||
(SELECT count(*) FROM articles WHERE featured = true AND published = true) AS featured_articles
|
||||
`);
|
||||
|
||||
console.log("seed_rows:");
|
||||
for (const [table, n] of results) {
|
||||
console.log(` ${table}: ${n}`);
|
||||
}
|
||||
console.log("db_counts:", JSON.stringify(counts.rows[0]));
|
||||
} finally {
|
||||
await client.end().catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
await main();
|
||||
Reference in new issue
Block a user