Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Feb 6, 2025
1 parent 5f3e51c commit 23db0ea
Show file tree
Hide file tree
Showing 30 changed files with 251 additions and 264 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Database } from '@stacksjs/database'
import { sql } from '@stacksjs/database'
import { sql } from '@stacksjs/database'

export async function up(db: Database<any>) {
await db.schema
Expand All @@ -9,4 +9,4 @@ export async function up(db: Database<any>) {
.addColumn('activity_id', 'integer', col => col.notNull())
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
.execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ export async function up(db: Database<any>) {
.addColumn('token', 'varchar(512)', col => col.unique())
.addColumn('plain_text_token', 'varchar(512)')
.addColumn('abilities', 'text')
.addColumn('team_id', 'integer', (col) =>
col.references('teams.id').onDelete('cascade')
)
.addColumn('team_id', 'integer', col =>
col.references('teams.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export async function up(db: Database<any>) {
.addColumn('exp_year', 'integer', col => col.notNull())
.addColumn('is_default', 'boolean')
.addColumn('provider_id', 'varchar(255)')
.addColumn('user_id', 'integer', (col) =>
col.references('users.id').onDelete('cascade')
)
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { Database } from '@stacksjs/database'

export async function up(db: Database<any>) {
await db.schema
.createTable('team_users')
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
.addColumn('team_id', 'integer')
.addColumn('user_id', 'integer')
.execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ export async function up(db: Database<any>) {
.createTable('subscribers')
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
.addColumn('subscribed', 'boolean')
.addColumn('user_id', 'integer', (col) =>
col.references('users.id').onDelete('cascade')
)
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ export async function up(db: Database<any>) {
.addColumn('amount', 'integer', col => col.notNull())
.addColumn('type', 'varchar(50)', col => col.notNull())
.addColumn('provider_id', 'varchar(255)')
.addColumn('payment_method_id', 'integer', (col) =>
col.references('payment_methods.id').onDelete('cascade')
)
.addColumn('user_id', 'integer', (col) =>
col.references('users.id').onDelete('cascade')
)
.addColumn('payment_method_id', 'integer', col =>
col.references('payment_methods.id').onDelete('cascade'))
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export async function up(db: Database<any>) {
.addColumn('trial_ends_at', 'varchar(255)')
.addColumn('ends_at', 'varchar(255)')
.addColumn('last_used_at', 'varchar(255)')
.addColumn('user_id', 'integer', (col) =>
col.references('users.id').onDelete('cascade')
)
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ export async function up(db: Database<any>) {
.addColumn('execution_time', 'integer')
.addColumn('deploy_script', 'varchar(255)')
.addColumn('terminal_output', 'varchar(255)')
.addColumn('user_id', 'integer', (col) =>
col.references('users.id').onDelete('cascade')
)
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Database } from '@stacksjs/database'
import { sql } from '@stacksjs/database'
import { sql } from '@stacksjs/database'

export async function up(db: Database<any>) {
await db.schema
Expand All @@ -17,4 +17,4 @@ export async function up(db: Database<any>) {
.addColumn('last_used_at', 'text')
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql.raw('CURRENT_TIMESTAMP')))
.execute()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export async function up(db: Database<any>) {
.addColumn('id', 'integer', col => col.primaryKey().autoIncrement())
.addColumn('title', 'varchar(255)')
.addColumn('body', 'varchar(255)')
.addColumn('user_id', 'integer', (col) =>
col.references('users.id').onDelete('cascade')
)
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
21 changes: 8 additions & 13 deletions storage/framework/core/orm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,26 @@ export async function getRelations(model: Model, modelName: string): Promise<Rel
for (const relationInstance of model[relation as keyof Model] as BaseRelation) {
let relationModel = relationInstance.model
let modelRelation: Model
let modelPath: string
if (isString(relationInstance)) {
relationModel = relationInstance
}

const modelRelationPath = path.userModelsPath(`${relationModel}.ts`)
const modelPath = path.userModelsPath(`${modelName}.ts`)
const userModelPath = path.userModelsPath(`${modelName}.ts`)
const coreModelPath = path.storagePath(`framework/defaults/models/${modelName}.ts`)
const coreModelRelationPath = path.storagePath(`framework/defaults/models/${relationModel}.ts`)

if (fs.existsSync(modelRelationPath))
modelRelation = (await import(modelRelationPath)).default as Model
else
modelRelation = (await import(coreModelRelationPath)).default as Model

if (fs.existsSync(userModelPath))
modelPath = userModelPath
else
modelPath = coreModelPath

const modelRelationTable = getTableName(modelRelation, modelRelationPath)
const table = getTableName(model, modelPath)
const modelRelationName = snakeCase(getModelName(modelRelation, modelRelationPath))
Expand Down Expand Up @@ -309,8 +316,6 @@ export async function writeModelNames(): Promise<void> {
}
}

fileString += ' | '

// Ensure the directory exists
const typesDir = path.dirname(path.typesPath(`src/model-names.ts`))
await fs.promises.mkdir(typesDir, { recursive: true })
Expand Down Expand Up @@ -949,16 +954,6 @@ export async function generateKyselyTypes(): Promise<void> {
text += ` ${tableName}: ${formattedTableName}\n`
}

for (const coreModelFile of coreModelFiles) {
const model = (await import(coreModelFile)).default as Model
const tableName = getTableName(model, coreModelFile)

const words = tableName.split('_')
const formattedTableName = `${words.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('')}Table`

text += ` ${tableName}: ${formattedTableName}\n`
}

text += 'passkeys: PasskeysTable\n'
text += 'migrations: MigrationsTable\n'

Expand Down
1 change: 0 additions & 1 deletion storage/framework/core/payments/src/billable/charge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const manageCharge: ManageCharge = (() => {
}
catch (error) {
log.error('Error creating refund:', error)
throw error
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/types/src/model-names.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type ModelNames = 'Project' | 'SubscriberEmail' | 'AccessToken' | 'Team' | 'Activity' | 'Subscriber' | 'Deployment' | 'Release' | 'User' | 'Post' | 'FailedJob' | 'Product' | 'PaymentMethod' | 'Transaction' | 'Job' | 'Subscription' | 'Error'
export type ModelNames = 'Activity' | 'Project' | 'FailedJob' | 'SubscriberEmail' | 'Product' | 'AccessToken' | 'PaymentMethod' | 'Team' | 'Subscriber' | 'Transaction' | 'Job' | 'Subscription' | 'Deployment' | 'Error' | 'Release' | 'User' | 'Post'
2 changes: 1 addition & 1 deletion storage/framework/core/types/src/table-names.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type TableNames = 'projects' | 'subscriber_emails' | 'personal_access_tokens' | 'team_users' | 'teams' | 'activities' | 'subscribers' | 'deployments' | 'releases' | 'team_users' | 'users' | 'posts' | 'failed_jobs' | 'products' | 'payment_methods' | 'transactions' | 'jobs' | 'subscriptions' | 'errors'
export type TableNames = 'activities' | 'projects' | 'failed_jobs' | 'subscriber_emails' | 'products' | 'personal_access_tokens' | 'payment_methods' | 'team_users' | 'teams' | 'subscribers' | 'transactions' | 'jobs' | 'subscriptions' | 'deployments' | 'errors' | 'releases' | 'team_users' | 'users' | 'posts'
14 changes: 7 additions & 7 deletions storage/framework/orm/routes.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { route } from '@stacksjs/router'

route.get('activities', 'storage/framework/actions/src/ActivityIndexOrmAction.ts')

route.get('activities/{id}', 'storage/framework/actions/src/ActivityShowOrmAction.ts')
route.get('users', 'UserIndexOrmAction')

route.post('users', 'UserStoreOrmAction')

route.get('users/{id}', 'UserShowOrmAction')

/actions/src/ActivityShowOrmAction.ts')

route.post('activities', 'storage/framework/actions/src/ActivityStoreOrmAction.ts')

route.patch('activities/{id}', 'storage/framework/actions/src/ActivityUpdateOrmAction.ts')

route.delete('activities/{id}', 'storage/framework/actions/src/ActivityDestroyOrmAction.ts')

route.get('users', 'UserIndexOrmAction')

route.post('users', 'UserStoreOrmAction')

route.get('users/{id}', 'UserShowOrmAction')
2 changes: 1 addition & 1 deletion storage/framework/orm/src/models/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface QueryOptions {

export class TransactionModel {
private readonly hidden: Array<keyof TransactionJsonResponse> = []
private readonly fillable: Array<keyof TransactionJsonResponse> = ['name', 'description', 'amount', 'type', 'provider_id', 'uuid', 'user_id', 'payment_method_id']
private readonly fillable: Array<keyof TransactionJsonResponse> = ['name', 'description', 'amount', 'type', 'provider_id', 'uuid', 'payment_method_id', 'user_id']
private readonly guarded: Array<keyof TransactionJsonResponse> = []
protected attributes: Partial<TransactionType> = {}
protected originalAttributes: Partial<TransactionType> = {}
Expand Down
16 changes: 8 additions & 8 deletions storage/framework/orm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ export interface PasskeysTable {
}

export interface Database {
activities: ActivitiesTable
projects: ProjectsTable
failed_jobs: FailedJobsTable
subscriber_emails: SubscriberEmailsTable
products: ProductsTable
personal_access_tokens: PersonalAccessTokensTable
payment_methods: PaymentMethodsTable
team_users: TeamUsersTable
teams: TeamsTable
activities: ActivitiesTable
subscribers: SubscribersTable
deployments: DeploymentsTable
releases: ReleasesTable
users: UsersTable
posts: PostsTable
failed_jobs: FailedJobsTable
products: ProductsTable
payment_methods: PaymentMethodsTable
transactions: TransactionsTable
jobs: JobsTable
subscriptions: SubscriptionsTable
deployments: DeploymentsTable
errors: ErrorsTable
releases: ReleasesTable
users: UsersTable
posts: PostsTable
passkeys: PasskeysTable
migrations: MigrationsTable
}
4 changes: 2 additions & 2 deletions storage/framework/requests/TransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface RequestDataTransaction {
amount: number
type: string
provider_id: string
user_id: number
payment_method_id: number
user_id: number
created_at?: Date
updated_at?: Date
}
Expand All @@ -29,8 +29,8 @@ export class TransactionRequest extends Request<RequestDataTransaction> implemen
public amount = 0
public type = ''
public provider_id = ''
public user_id = 0
public payment_method_id = 0
public user_id = 0
public created_at = new Date()
public updated_at = new Date()
public uuid = ''
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/server-auto-imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@
"transactionRequest": true,
"userRequest": true
}
}
}
Loading

0 comments on commit 23db0ea

Please sign in to comment.