Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
70 lines (56 loc) · 1.96 KB

File metadata and controls

70 lines (56 loc) · 1.96 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Seed script — creates the first workspace and admin user.
* Run once after first migration:
* DATABASE_URL=... npx tsx scripts/seed.ts
*/
import postgres from 'postgres';
import { drizzle } from 'drizzle-orm/postgres-js';
import * as schema from '../lib/db/schema/index';
import { seedLayouts } from './seed/layouts';
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
console.error('DATABASE_URL is required');
process.exit(1);
}
const client = postgres(connectionString);
const db = drizzle(client, { schema });
async function seed() {
console.log('Seeding database...');
// Check if workspace already exists
const existing = await db.query.workspaces.findFirst();
if (existing) {
console.log('Workspace already exists — seeding layouts only.');
await seedLayouts(db as never, existing.id);
await client.end();
return;
}
const [workspace] = await db
.insert(schema.workspaces)
.values({ name: 'My Workspace' })
.returning();
if (!workspace) throw new Error('Failed to create workspace');
const adminEmail = process.env.ADMIN_EMAIL ?? 'admin@deckforge.test';
const adminName = process.env.ADMIN_NAME ?? 'Admin';
const [admin] = await db
.insert(schema.users)
.values({
workspaceId: workspace.id,
name: adminName,
email: adminEmail.toLowerCase(),
role: 'admin',
})
.returning();
if (!admin) throw new Error('Failed to create admin user');
console.log(`Workspace created: "${workspace.name}" (${workspace.id})`);
console.log(`Admin user created: ${admin.email} (${admin.id})`);
console.log('Seeding built-in layouts...');
await seedLayouts(db as never, workspace.id);
console.log('');
console.log(`To log in on production, run:`);
console.log(` DATABASE_URL=... APP_URL=https://yourdomain.com npx tsx scripts/create-magic-link.ts ${admin.email}`);
await client.end();
}
seed().catch((err) => {
console.error(err);
process.exit(1);
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.