Create model fields from Migration #2826
tuliovargas
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
This is a great idea, like the Laravel Eloquent. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Need someone from the community to help us building the tooling. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'd like to suggest the following enhancement, once We have a migration defined, it would be possible to have a command-line such as:
node ace make:model user -f
Then it'd create a new model with the declared structure from migration.
Example Migration
protected tableName = 'users'
public async up () {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.string('name').notNullable()
table.string('email').unique().notNullable()
table.text('user_agent').notNullable()
table.integer('phone').notNullable()
table.string('campaign').notNullable()
table.timestamp('created_at', { useTz: true }).notNullable().defaultTo(this.now())
table.timestamp('updated_at', { useTz: true }).notNullable().defaultTo(this.now())
Example Auto Model creation
@column({ isPrimary: true })
public id: number
@column()
public name: string
@column()
public email: string
@column()
public user_agent: string
@column()
public phone: number
@column()
public campaign: string
@column.dateTime({ autoCreate: true })
public createdAt: DateTime
@column.dateTime({ autoCreate: true, autoUpdate: true })
public updatedAt: DateTime
Beta Was this translation helpful? Give feedback.
All reactions