yii2-openapi icon indicating copy to clipboard operation
yii2-openapi copied to clipboard

timestamp migrations do not work in MariaDB

Open cebe opened this issue 3 years ago • 4 comments

   Customer:
      description: customer is the one that orders a campaign
      type: object
      required:
        - id
        - name
        - created_at

      properties:
        id:
          type: integer
        name:
          type: string
          maxLength: 100

        created_at:
          type: string
          format: datetime
          nullable: false
          x-db-type: datetime
          default: CURRENT_TIMESTAMP
        updated_at:
          type: string
          format: datetime
          default: null
          nullable: true
          x-db-type: datetime

generates a migration:

class m220524_140002_change_table_customers extends \yii\db\Migration
{
    public function up()
    {
        $this->alterColumn('{{%customers}}', 'created_at', $this->timestamp()->notNull()->defaultExpression("CURRENT_TIMESTAMP"));
    }

    public function down()
    {
        $this->alterColumn('{{%customers}}', 'created_at', $this->timestamp()->notNull()->defaultExpression("CURRENT_TIMESTAMP"));
    }
}

cebe avatar May 24 '22 14:05 cebe

similar behavior for ENUM colums, existing column gets an update which removes the "string type":

      properties:
        system:
          type: string
          maxLength: 10
          enum:
            - mail
            - test
            - other

generates:

class m220524_140005_change_table_mailings extends \yii\db\Migration
{
    public function up()
    {
        $this->alterColumn('{{%mailings}}', 'system', $this->notNull());
    }

    public function down()
    {
        $this->alterColumn('{{%mailings}}', 'system', $this->string(10)->notNull());
    }
}

cebe avatar May 24 '22 14:05 cebe

          x-db-type: datetime

this should explicitly generate "datetime" type and not "timestamp".

cebe avatar May 24 '22 14:05 cebe

Fields with json type also create error like as in enum

Also there are separate errors related json. It will require separate issue.

SOHELAHMED7 avatar Sep 30 '22 11:09 SOHELAHMED7

Moved enum issue to separate issue

So that this issue focus only on timestamp issue.

SOHELAHMED7 avatar Sep 30 '22 11:09 SOHELAHMED7

This issue can be closed.

SOHELAHMED7 avatar Dec 29 '22 12:12 SOHELAHMED7