Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmichael123 committed Jan 10, 2025
1 parent 665b2c4 commit 7732f7a
Show file tree
Hide file tree
Showing 25 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export async function up(db: Database<any>) {
.addColumn('description', 'varchar(255)')
.addColumn('path', 'varchar(255)')
.addColumn('is_personal', 'boolean')
.addColumn('accesstoken_id', 'integer', col =>
col.references('personal_access_tokens.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,18 +11,6 @@ export async function up(db: Database<any>) {
.addColumn('password', 'varchar(255)', col => col.notNull())
.addColumn('job_title', 'varchar(255)', col => col.notNull())
.addColumn('stripe_id', 'varchar(255)')
.addColumn('team_id', 'integer', col =>
col.references('teams.id').onDelete('cascade'))
.addColumn('deployment_id', 'integer', col =>
col.references('deployments.id').onDelete('cascade'))
.addColumn('post_id', 'integer', col =>
col.references('posts.id').onDelete('cascade'))
.addColumn('paymentmethod_id', 'integer', col =>
col.references('payment_methods.id').onDelete('cascade'))
.addColumn('transaction_id', 'integer', col =>
col.references('transactions.id').onDelete('cascade'))
.addColumn('subscription_id', 'integer', col =>
col.references('subscriptions.id').onDelete('cascade'))
.addColumn('public_passkey', 'text')
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export async function up(db: Database<any>) {
.addColumn('provider_id', 'varchar(255)')
.addColumn('user_id', 'integer', col =>
col.references('users.id').onDelete('cascade'))
.addColumn('transaction_id', 'integer', col =>
col.references('transactions.id').onDelete('cascade'))
.addColumn('created_at', 'timestamp', col => col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
.addColumn('updated_at', 'timestamp')
.execute()
Expand Down
3 changes: 3 additions & 0 deletions storage/framework/core/database/src/drivers/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ async function createTableMigration(modelPath: string) {

if (otherModelRelations?.length) {
for (const modelRelation of otherModelRelations) {
if (!modelRelation.foreignKey)
continue

migrationContent += ` .addColumn('${modelRelation.foreignKey}', 'integer', (col) =>
col.references('${modelRelation.relationTable}.id').onDelete('cascade')
) \n`
Expand Down
2 changes: 1 addition & 1 deletion storage/framework/core/orm/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function getRelations(model: Model, modelName: string): Promise<Rel
|| getPivotTableName(plural(formattedModelName), plural(modelRelation.table || '')),
}

if (relation === 'belongsTo')
if (['belongsToMany', 'belongsTo'].includes(relation))
relationshipData.foreignKey = ''

relationships.push(relationshipData)
Expand Down
4 changes: 2 additions & 2 deletions storage/framework/orm/src/models/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface QueryOptions {

export class TeamModel {
private hidden = []
private fillable = ['name', 'company_name', 'email', 'billing_email', 'status', 'description', 'path', 'is_personal', 'uuid', 'user_id']
private fillable = ['name', 'company_name', 'email', 'billing_email', 'status', 'description', 'path', 'is_personal', 'uuid']
private softDeletes = false
protected selectFromQuery: any
protected withRelations: string[]
Expand Down Expand Up @@ -773,7 +773,7 @@ export class TeamModel {
throw new HttpError(500, 'Relation Error!')

const results = await db.selectFrom('team_users')
.where('team_id', '=', this.id)
.where('', '=', this.id)
.selectAll()
.execute()

Expand Down
4 changes: 2 additions & 2 deletions storage/framework/orm/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface QueryOptions {

export class UserModel {
private hidden = ['password']
private fillable = ['name', 'email', 'job_title', 'password', 'stripe_id', 'uuid', 'two_factor_secret', 'public_key', 'team_id']
private fillable = ['name', 'email', 'job_title', 'password', 'stripe_id', 'uuid', 'two_factor_secret', 'public_key']
private softDeletes = false
protected selectFromQuery: any
protected withRelations: string[]
Expand Down Expand Up @@ -875,7 +875,7 @@ export class UserModel {
throw new HttpError(500, 'Relation Error!')

const results = await db.selectFrom('team_users')
.where('user_id', '=', this.id)
.where('', '=', this.id)
.selectAll()
.execute()

Expand Down
2 changes: 0 additions & 2 deletions storage/framework/requests/TeamRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface RequestDataTeam {
description: string
path: string
is_personal: boolean
user_id: number
created_at?: Date
updated_at?: Date
}
Expand All @@ -34,7 +33,6 @@ export class TeamRequest extends Request<RequestDataTeam> implements TeamRequest
public description = ''
public path = ''
public is_personal = false
public user_id = 0
public created_at = new Date()
public updated_at = new Date()

Expand Down
2 changes: 0 additions & 2 deletions storage/framework/requests/UserRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface RequestDataUser {
email: string
job_title: string
password: string
team_id: number
created_at?: Date
updated_at?: Date
}
Expand All @@ -26,7 +25,6 @@ export class UserRequest extends Request<RequestDataUser> implements UserRequest
public email = ''
public job_title = ''
public password = ''
public team_id = 0
public created_at = new Date()
public updated_at = new Date()
public uuid = ''
Expand Down
8 changes: 2 additions & 6 deletions storage/framework/types/requests.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ interface RequestDataTeam {
description: string
path: string
is_personal: boolean
user_id: number
created_at?: Date
updated_at?: Date
}
export interface TeamRequestType extends Request {
validate: (attributes?: CustomAttributes) => void
get: ((key: 'id') => number) & ((key: 'name' | 'company_name' | 'email' | 'billing_email' | 'status' | 'description' | 'path') => string) & ((key: 'is_personal') => boolean) & ((key: 'user_id') => string)
get: ((key: 'id') => number) & ((key: 'name' | 'company_name' | 'email' | 'billing_email' | 'status' | 'description' | 'path') => string) & ((key: 'is_personal') => boolean)

all: () => RequestDataTeam
id: number
Expand All @@ -105,7 +104,6 @@ export interface TeamRequestType extends Request {
description: string
path: string
is_personal: boolean
user_id: number
created_at?: Date
updated_at?: Date
}
Expand Down Expand Up @@ -183,21 +181,19 @@ interface RequestDataUser {
email: string
job_title: string
password: string
team_id: number
created_at?: Date
updated_at?: Date
}
export interface UserRequestType extends Request {
validate: (attributes?: CustomAttributes) => void
get: ((key: 'id') => number) & ((key: 'name' | 'email' | 'job_title' | 'password') => string) & ((key: 'team_id') => string)
get: ((key: 'id') => number) & ((key: 'name' | 'email' | 'job_title' | 'password') => string)

all: () => RequestDataUser
id: number
name: string
email: string
job_title: string
password: string
team_id: number
created_at?: Date
updated_at?: Date
}
Expand Down

0 comments on commit 7732f7a

Please sign in to comment.