adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.03k stars 189 forks source link

Default templates #906

Closed rawahamid closed 1 year ago

rawahamid commented 1 year ago

Prerequisites

When generate model, migration or seeder add feature to change the default template for avoid change every generated file to the template that want for more info like publish stubs in laravel

Why this feature is required (specific use-cases will be appreciated)?

simple example i want to change the snake case for created_at, updated_at to createdAt, updatedAt inside migration-make.txt file

import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class extends BaseSchema {
  protected tableName = '{{#toTableName}}{{ filename }}{{/toTableName}}'

  public async up () {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')

      /**
       * Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
       */
      table.timestamp('created_at', { useTz: true })
      table.timestamp('updated_at', { useTz: true })
    })
  }

  public async down () {
    this.schema.dropTable(this.tableName)
  }
}

To

import BaseSchema from '@ioc:Adonis/Lucid/Schema'

export default class extends BaseSchema {
  protected tableName = '{{#toTableName}}{{ filename }}{{/toTableName}}'

  public async up () {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')

      /**
       * Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL
       */
      table.timestamp('createdAt', { useTz: true })
      table.timestamp('updatedAt', { useTz: true })
    })
  }

  public async down () {
    this.schema.dropTable(this.tableName)
  }
}
mastermunj commented 1 year ago

Seems this feature is coming soon in v6. Have a look at https://twitter.com/AmanVirk1/status/1612000895788797957

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.