Skip to content

Commit 42ed99f

Browse files
chore: wip
1 parent 928842b commit 42ed99f

28 files changed

+1745
-62
lines changed

app/Actions/EmailSubscribeAction.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Action } from '@stacksjs/actions'
2+
import { request } from '@stacksjs/router'
3+
import SubscriberEmail from '../../storage/framework/orm/src/models/SubscriberEmail'
4+
5+
export default new Action({
6+
name: 'EmailSubscribeAction',
7+
description: 'Save emails from subscribe oage',
8+
method: 'POST',
9+
async handle() {
10+
const email = request.get('email')
11+
12+
const model = await SubscriberEmail.create({ email })
13+
14+
return model
15+
},
16+
})

app/Models/SubscriberEmail.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// soon, these will be auto-imported
2+
import { faker } from '@stacksjs/faker'
3+
import type { Model } from '@stacksjs/types'
4+
import { schema } from '@stacksjs/validation'
5+
6+
export default {
7+
name: 'SubscriberEmail', // defaults to the sanitized file name
8+
table: 'subscriber_emails', // defaults to the lowercase, plural name of the model name (or the name of the model file)
9+
primaryKey: 'id', // defaults to `id`
10+
autoIncrement: true, // defaults to true
11+
12+
traits: {
13+
useAuth: true, // defaults to false, `authenticatable` used as an alias
14+
useTimestamps: true, // defaults to true, `timestampable` used as an alias
15+
useSoftDeletes: true, // defaults to false, `softDeletable` used as an alias
16+
17+
useSeeder: {
18+
// defaults to a count of 10, `seedable` used as an alias
19+
count: 100,
20+
},
21+
// useUuid: true, // defaults to false
22+
},
23+
24+
attributes: {
25+
email: {
26+
unique: true,
27+
validator: {
28+
rule: schema.string().email(),
29+
message: 'Email must be a valid email address',
30+
},
31+
32+
factory: () => faker.internet.email(),
33+
},
34+
},
35+
36+
} satisfies Model

database/migrations/1716297812598-create-access_tokens-table.ts

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

database/migrations/1716297812601-create-projects-table.ts renamed to database/migrations/1716822278688-create-projects-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { sql } from '@stacksjs/database'
44
export async function up(db: Database<any>) {
55
await db.schema
66
.createTable('projects')
7-
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
88
.addColumn('name', 'varchar(255)')
99
.addColumn('description', 'varchar(255)')
1010
.addColumn('url', 'varchar(255)')
1111
.addColumn('status', 'varchar(255)')
12-
.addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
12+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
1313
.addColumn('updated_at', 'timestamp')
1414
.execute()
1515
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Database } from '@stacksjs/database'
2+
import { sql } from '@stacksjs/database'
3+
4+
export async function up(db: Database<any>) {
5+
await db.schema
6+
.createTable('subscriber_emails')
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
8+
.addColumn('email', 'varchar(255)', col => col.unique())
9+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
10+
.addColumn('updated_at', 'timestamp')
11+
.addColumn('deleted_at', 'timestamp')
12+
.execute()
13+
}

database/migrations/1716297812602-create-deployments-table.ts renamed to database/migrations/1716822278690-create-deployments-table.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ import { sql } from '@stacksjs/database'
44
export async function up(db: Database<any>) {
55
await db.schema
66
.createTable('deployments')
7-
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
8-
.addColumn('commitSha', 'varchar(512)', (col) => col.unique())
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
8+
.addColumn('commitSha', 'varchar(512)', col => col.unique())
99
.addColumn('commitMessage', 'varchar(255)')
1010
.addColumn('branch', 'varchar(255)')
1111
.addColumn('status', 'varchar(255)')
1212
.addColumn('executionTime', 'integer')
1313
.addColumn('deployScript', 'varchar(255)')
1414
.addColumn('terminalOutput', 'varchar(255)')
15-
.addColumn('user_id', 'integer', (col) => col.references('users.id').onDelete('cascade'))
16-
.addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
15+
.addColumn('user_id', 'integer', (col) =>
16+
col.references('users.id').onDelete('cascade')
17+
)
18+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
1719
.addColumn('updated_at', 'timestamp')
1820
.execute()
1921
}

database/migrations/1716297812600-create-users-table.ts renamed to database/migrations/1716822278690-create-users-table.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { sql } from '@stacksjs/database'
44
export async function up(db: Database<any>) {
55
await db.schema
66
.createTable('users')
7-
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
88
.addColumn('name', 'varchar(255)')
9-
.addColumn('email', 'varchar(255)', (col) => col.unique())
9+
.addColumn('email', 'varchar(255)', col => col.unique())
1010
.addColumn('jobTitle', 'varchar(255)')
1111
.addColumn('password', 'varchar(255)')
12-
.addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
12+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
1313
.addColumn('updated_at', 'timestamp')
1414
.addColumn('deleted_at', 'timestamp')
1515
.execute()

database/migrations/1716297812600-create-subscribers-table.ts renamed to database/migrations/1716822278691-create-subscribers-table.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { sql } from '@stacksjs/database'
44
export async function up(db: Database<any>) {
55
await db.schema
66
.createTable('subscribers')
7-
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
88
.addColumn('subscribed', 'boolean')
9-
.addColumn('user_id', 'integer', (col) => col.references('users.id').onDelete('cascade'))
10-
.addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
9+
.addColumn('user_id', 'integer', (col) =>
10+
col.references('users.id').onDelete('cascade')
11+
)
12+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
1113
.addColumn('updated_at', 'timestamp')
1214
.execute()
1315
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Database } from '@stacksjs/database'
2+
import { sql } from '@stacksjs/database'
3+
4+
export async function up(db: Database<any>) {
5+
await db.schema
6+
.createTable('access_tokens')
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
8+
.addColumn('name', 'varchar(255)')
9+
.addColumn('token', 'varchar(512)', col => col.unique())
10+
.addColumn('plainTextToken', 'varchar(512)')
11+
.addColumn('abilities', sql`enum('read', 'write', 'admin', 'read|write', 'read|admin', 'write|admin', 'read|write|admin')`)
12+
.addColumn('team_id', 'integer', (col) =>
13+
col.references('teams.id').onDelete('cascade')
14+
)
15+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
16+
.addColumn('updated_at', 'timestamp')
17+
.execute()
18+
}

database/migrations/1716297812599-create-posts-table.ts renamed to database/migrations/1716822278692-create-posts-table.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { sql } from '@stacksjs/database'
44
export async function up(db: Database<any>) {
55
await db.schema
66
.createTable('posts')
7-
.addColumn('id', 'integer', (col) => col.primaryKey().autoIncrement())
7+
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
88
.addColumn('title', 'varchar(255)')
99
.addColumn('body', 'varchar(255)')
10-
.addColumn('user_id', 'integer', (col) => col.references('users.id').onDelete('cascade'))
11-
.addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
10+
.addColumn('user_id', 'integer', (col) =>
11+
col.references('users.id').onDelete('cascade')
12+
)
13+
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
1214
.addColumn('updated_at', 'timestamp')
1315
.execute()
1416
}

0 commit comments

Comments
 (0)