Skip to content

Commit e336df7

Browse files
committed
chore: wip
1 parent 20b260c commit e336df7

File tree

1 file changed

+31
-1
lines changed
  • .stacks/core/database/src/migrations

1 file changed

+31
-1
lines changed

.stacks/core/database/src/migrations/index.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ interface Model {
1515
columns: Column[]
1616
}
1717

18+
interface ModelData {
19+
[key: string]: any;
20+
}
21+
1822
function generatePrismaSchema(models: Model[], path: string): void {
1923
let schema = `datasource db {
2024
provider = "postgresql"
@@ -52,7 +56,9 @@ generator client {
5256

5357
schema += '}\n\n'
5458
}
59+
5560
path = '.stacks/database/schema.prisma'
61+
5662
fs.writeFile(path, schema, (err) => {
5763
if (err) {
5864
console.error(`Error writing schema file: ${err.message}`)
@@ -62,4 +68,28 @@ generator client {
6268
})
6369
}
6470

65-
export { generatePrismaSchema }
71+
function readModelsFromFolder(folderPath: string): ModelData[] {
72+
const models: ModelData[] = [];
73+
74+
fs.readdirSync(folderPath).forEach((file) => {
75+
if (file.endsWith('.ts')) {
76+
const filePath = `${folderPath}/${file}`;
77+
const fileContents = fs.readFileSync(filePath, 'utf-8');
78+
79+
const regex = /return\s*{([^}]*)}/m;
80+
const match = fileContents.match(regex);
81+
82+
if (match) {
83+
const modelData = eval(`({${match[1]}})`);
84+
models.push(modelData);
85+
}
86+
}
87+
});
88+
89+
return models;
90+
}
91+
92+
export {
93+
generatePrismaSchema,
94+
readModelsFromFolder
95+
}

0 commit comments

Comments
 (0)