Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite timestamps using ALTER TABLE broken #1001

Open
sitedyno opened this issue Jun 26, 2021 · 1 comment
Open

Sqlite timestamps using ALTER TABLE broken #1001

sitedyno opened this issue Jun 26, 2021 · 1 comment

Comments

@sitedyno
Copy link
Contributor

sitedyno commented Jun 26, 2021

From here; https://www.sqlite.org/lang_altertable.html

  1. ALTER TABLE ADD COLUMN
    ...
  • The column may not have a default value of CURRENT_TIME, CURRENT_DATE, CURRENT_TIMESTAMP, or an expression in parentheses.
└─[0] <git:(update-to-4.0.7 2065ce9 ✈ )> sqlite3 my_app "select * from taxonomies;"
1||1|1|1|2|(datetime(CURRENT_TIMESTAMP, 'utc'))|
2||2|1|3|4|(datetime(CURRENT_TIMESTAMP, 'utc'))|
3||3|2|1|2|(datetime(CURRENT_TIMESTAMP, 'utc'))|
└─[1] <git:(update-to-4.0.7 2065ce9 ✈ )> sqlite3 my_app ".schema taxonomies"
CREATE TABLE IF NOT EXISTS "taxonomies" (`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `parent_id` INTEGER NULL, `term_id` INTEGER NULL, `vocabulary_id` INTEGER NULL, `lft` INTEGER NULL, `rght` INTEGER NULL, `created` TIMESTAMP_TEXT NOT NULL DEFAULT '(datetime(CURRENT_TIMESTAMP, ''utc''))', `modified` TIMESTAMP_TEXT NULL, CONSTRAINT `fk_taxonomies2terms`, CONSTRAINT `fk_taxonomies2vocabularies`);

This (datetime(CURRENT_TIMESTAMP, 'utc')) is fine for CREATE TABLE, but not allowed for ALTAR TABLE :(

This only effects croogo/croogo/Taxonomy/config/Migrations/20191120012924_TaxonomySyncTimestampFields.php

I think the only way to work around this is by making another Migration (only for Sqlite) that creates new tables, copies data to the new table, drops the old table, then renames the new table to the old one. I will try to do a pull request if this sounds acceptable.

@rchavik
Copy link
Member

rchavik commented Jun 28, 2021

If it only affects sqlite, should we bother? Migrations are typically needed for prod which are typically mysql/postgresql in croogo's case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants