Skip to content

Commit 90d41b3

Browse files
committed
chore: wip
1 parent 86826ab commit 90d41b3

File tree

1 file changed

+53
-2
lines changed
  • .stacks/core/database/src/migrations

1 file changed

+53
-2
lines changed
Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
1-
function migrations() {
1+
interface Column {
2+
name: string;
3+
type: string;
4+
required?: boolean;
5+
unique?: boolean;
6+
default?: string;
7+
}
8+
9+
interface Model {
10+
name: string;
11+
columns: Column[];
12+
}
213

14+
function generatePrismaSchema(models: Model[]): string {
15+
let schema = `datasource db {
16+
provider = "postgresql"
17+
url = env("DATABASE_URL")
318
}
419
5-
export { migrations }
20+
generator client {
21+
provider = "prisma-client-js"
22+
}
23+
24+
`;
25+
26+
for (const model of models) {
27+
schema += `model ${model.name} {
28+
id Int @id @default(autoincrement())
29+
createdAt DateTime @default(now())
30+
updatedAt DateTime @updatedAt()
31+
`;
32+
33+
for (const column of model.columns) {
34+
let columnSchema = ` ${column.name} ${column.type}`;
35+
36+
if (column.required) {
37+
columnSchema += ' @required';
38+
}
39+
40+
if (column.unique) {
41+
columnSchema += ' @unique';
42+
}
43+
44+
if (column.default) {
45+
columnSchema += ` @default(${column.default})`;
46+
}
47+
48+
columnSchema += '\n';
49+
schema += columnSchema;
50+
}
51+
52+
schema += '}\n\n';
53+
}
54+
55+
return schema;
56+
}

0 commit comments

Comments
 (0)