Skip to content

Commit c686a67

Browse files
committed
chore: wip
1 parent 4301e3d commit c686a67

File tree

30 files changed

+97
-161
lines changed

30 files changed

+97
-161
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// import { database } from '@stacksjs/config'

.stacks/core/actions/src/dev/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { frameworkPath, vitePath } from '@stacksjs/path'
44
// import { parseOptions, runCommand } from '@stacksjs/cli'
55
// import type { DeployOptions } from '@stacksjs/types'
66

7-
// console.log('running devd components')
7+
// console.log('running dev components')
88

99
// const options: DeployOptions = parseOptions()
1010

.stacks/core/actions/src/dev/docs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { frameworkPath } from '@stacksjs/path'
33

44
await runCommand('bun run dev', {
55
cwd: frameworkPath('docs'),
6-
verbose: true,
6+
// verbose: true,
77
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { generateMigrationFile } from '@stacksjs/database'
2+
3+
generateMigrationFile({
4+
name: 'CreateUsersTable',
5+
up: `
6+
CREATE TABLE users (
7+
id SERIAL PRIMARY KEY,
8+
email VARCHAR(255) NOT NULL,
9+
password VARCHAR(255) NOT NULL,
10+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
11+
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
12+
);
13+
`,
14+
down: `
15+
DROP TABLE users;
16+
`,
17+
})
18+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// loops over all the models to generate the model classes
2+
3+
// export class User {
4+
// create(user: { name: string }) {
5+
// return
6+
// }
7+
8+
// createMany(users: { name: string }[]) {
9+
// return
10+
// }
11+
// }

.stacks/core/actions/src/seed.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 30 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,10 @@
11
// import { storage } from '@stacksjs/storage'
2-
// import { frameworkPath, projectPath } from '@stacksjs/path'
2+
import { path as p } from '@stacksjs/path'
33
// import type { Model, SchemaOptions } from '@stacksjs/types'
44
// import { titleCase } from '@stacksjs/strings'
55

66
// const { fs } = storage
77

8-
// function generatePrismaSchema(models: Model[], path: string, options: SchemaOptions): void {
9-
// let schema = `datasource db {
10-
// provider = "${options.database}"
11-
// url = env.DATABASE_URL
12-
// }
13-
14-
// generator client {
15-
// provider = "prisma-client-js"
16-
// }
17-
18-
// `
19-
20-
// for (const model of models) {
21-
// schema += `model ${model.name} {
22-
// id Int @id @default(autoincrement())
23-
// `
24-
25-
// for (const fieldName in model.fields) {
26-
// const field = model.fields[fieldName]
27-
28-
// let columnSchema = ` ${fieldName} ${field.type}`
29-
30-
// if (field.required)
31-
// columnSchema += ' @required'
32-
33-
// if (field.unique)
34-
// columnSchema += ' @unique'
35-
36-
// if (field.default)
37-
// columnSchema += ` @default(${field.default})`
38-
39-
// columnSchema += '\n'
40-
// schema += columnSchema
41-
// }
42-
43-
// if (model.hasOne) {
44-
// schema += ` ${model.hasOne} ${titleCase(model.hasOne)}?`
45-
// schema += ` @relation(fields: [${model.hasOne}Id], references: [id])\n`
46-
// schema += ` ${model.hasOne}Id Int\n`
47-
// }
48-
49-
// if (model.belongsToMany) {
50-
// schema += ` ${model.belongsToMany} ${titleCase(model.belongsToMany)}`
51-
// schema += ` @relation(fields: [${model.belongsToMany}Id], references: [id])\n`
52-
// schema += ` ${model.belongsToMany}Id Int\n`
53-
// }
54-
55-
// if (model.hasMany) {
56-
// schema += ` ${model.hasMany} ${titleCase(model.hasMany)}[]`
57-
// schema += ` @relation(fields: [id], references: [${model.name?.toLowerCase()}Id])\n`
58-
// }
59-
60-
// if (model.hasThrough) {
61-
// schema += ` ${model.hasThrough.model} ${titleCase(model.hasThrough.model)}[]`
62-
// schema += ` @relation("${model.hasThrough.using}")`
63-
// schema += ` ${model.hasThrough.using} ${titleCase(model.hasThrough.using)}`
64-
// schema += ` @relation("${model.hasThrough.through}")`
65-
// schema += ` ${model.hasThrough.through} ${titleCase(model.hasThrough.through)}`
66-
// schema += ` @relation(fields: [${model.hasThrough.using}], references: [id])\n`
67-
// }
68-
69-
// schema += ' createdAt DateTime @default(now())\n'
70-
// schema += ' updatedAt DateTime @updatedAt()\n'
71-
// schema += '}\n\n'
72-
73-
// if (model.hasMany) {
74-
// schema += `model ${titleCase(model.hasMany)} {
75-
// id Int @id @default(autoincrement())
76-
// createdAt DateTime @default(now())
77-
// updatedAt DateTime @updatedAt()
78-
// ${model.name?.toLowerCase()}Id Int
79-
// ${model.name?.toLowerCase()} ${titleCase(model.name)}
80-
// @relation(fields: [${model.name?.toLowerCase()}Id], references: [id])
81-
// }\n\n`
82-
// }
83-
84-
// if (model.hasOne || model.belongsToMany) {
85-
// const relatedModelName = model.hasOne || model.belongsToMany
86-
// schema += `model ${titleCase(relatedModelName)} {
87-
// id Int @id @default(autoincrement())
88-
// createdAt DateTime @default(now())
89-
// updatedAt DateTime @updatedAt()
90-
// ${model.name?.toLowerCase()} ${titleCase(model.name)}?
91-
// ${model.name?.toLowerCase()}Id Int?
92-
// @unique
93-
// }\n\n`
94-
// }
95-
// }
96-
97-
// if (!fs.existsSync(frameworkPath('database')))
98-
// fs.mkdirSync(frameworkPath('database'))
99-
100-
// fs.writeFile(path, schema, (err) => {
101-
// if (err)
102-
// console.error(`Error writing schema file: ${err.message}`)
103-
// else
104-
// // eslint-disable-next-line no-console
105-
// console.log(`Schema file generated successfully at path: ${path}`)
106-
// })
107-
// }
108-
1098
// function readModelsFromFolder(folderPath: string): Promise<Model[]> {
1109
// return new Promise((resolve, reject) => {
11110
// const models: Model[] = []
@@ -140,9 +39,32 @@
14039
// generatePrismaSchema(models, path, options)
14140
// }
14241

143-
// export {
144-
// migrate,
145-
// }
146-
147-
const migrate = 'wip'
148-
export { migrate }
42+
export interface MigrationOptions {
43+
name: string
44+
up: string
45+
down: string
46+
}
47+
48+
export function generateMigrationFile(options: MigrationOptions) {
49+
const { name, up, down } = options
50+
51+
const timestamp = new Date().getTime()
52+
const fileName = `${timestamp}-${name}.ts`
53+
const filePath = p.frameworkPath(`database/migrations/${fileName}`)
54+
const fileContent = `
55+
import { Migration } from '@stacksjs/database'
56+
57+
export default new Migration({
58+
name: '${name}',
59+
up: \`
60+
${up}
61+
\`,
62+
down: \`
63+
${down}
64+
\`,
65+
})
66+
`
67+
fs.writeFileSync(filePath, fileContent)
68+
69+
console.log(`Created migration file: ${fileName}`)
70+
}

.stacks/core/docs/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { defineConfig } from 'vitepress'
22
import { path as p } from '@stacksjs/path'
3-
import { docs } from '@stacksjs/config'
3+
import { docs, app } from '@stacksjs/config'
44
import { docsEngine } from '../../vite/src/plugin/docs'
55

66
const defaultConfig = {
7-
title: 'StacksJS',
7+
title: `${app.name} Documentation`,
8+
89
vite: {
910
envDir: p.projectPath(),
1011
envPrefix: 'FRONTEND_',
12+
1113
server: {
1214
host: 'docs.stacks.test',
1315
port: 3333,
14-
open: true,
1516
},
1617

1718
plugins: [

.stacks/core/orm/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
// })
2424
// }
2525

26+
// if (database.driver === 'sqlite') {
27+
// dialect = new SqliteDialect()
28+
// }
29+
2630
// const db = new QueryBuilder({
2731
// dialect,
2832
// })
2933

34+
// const user = User.find(1)
35+
3036
// export async function find(tableName: string, id: number) {
3137
// const result = await db
3238
// .selectFrom(tableName)

0 commit comments

Comments
 (0)