Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

timestamp migrations do not work in MariaDB #100

Closed
cebe opened this issue May 24, 2022 · 5 comments · Fixed by #103 or #112
Closed

timestamp migrations do not work in MariaDB #100

cebe opened this issue May 24, 2022 · 5 comments · Fixed by #103 or #112
Labels
bug Something isn't working

Comments

@cebe
Copy link
Owner

cebe commented May 24, 2022

   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 cebe added the bug Something isn't working label May 24, 2022
@cebe cebe changed the title timestamp migrations do not work in MySQL timestamp migrations do not work in MariaDB May 24, 2022
@cebe
Copy link
Owner Author

cebe commented May 24, 2022

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
Copy link
Owner Author

cebe commented May 24, 2022

          x-db-type: datetime

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

@SOHELAHMED7
Copy link
Contributor

SOHELAHMED7 commented Sep 30, 2022

Fields with json type also create error like as in enum

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

@SOHELAHMED7
Copy link
Contributor

SOHELAHMED7 commented Sep 30, 2022

Moved enum issue to separate issue

So that this issue focus only on timestamp issue.

@SOHELAHMED7
Copy link
Contributor

This issue can be closed.

@cebe cebe closed this as completed in #112 Dec 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants