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

CLI Schema import causes crash. #12042

Closed
3 tasks done
stefan1968 opened this issue Mar 8, 2022 · 5 comments · Fixed by #12716
Closed
3 tasks done

CLI Schema import causes crash. #12042

stefan1968 opened this issue Mar 8, 2022 · 5 comments · Fixed by #12716
Labels

Comments

@stefan1968
Copy link

Preflight Checklist

Describe the Bug

I'm attempting to apply a schema to another clean instance of Directus, but it's throwing an error and crashing.

Screenshot attached.

To Reproduce

Export a schema with a date/timestamp?

Errors Shown

Screenshot 2022-03-08 at 23 02 08

What version of Directus are you using?

9.6.0

What version of Node.js are you using?

16.4.0

What database are you using?

Postgres 13

What browser are you using?

Chrome

What operating system are you using?

Docker

How are you deploying Directus?

Docker

@rijkvanzanten
Copy link
Member

@stefan1968 Did the instance where you created the snapshot use the same database? (Postgres 13)

@stefan1968
Copy link
Author

Yes, exactly the same. The only difference, the schema was exported from a directus version 9.5.1 instance and attempted to import from a 9.6.0, the postgres versions are identical however. I can supply the schema if it helps?

@azrikahar
Copy link
Contributor

A schema will be helpful indeed! Just so we can be on the same page when reproducing it 👍

With that said, I also just noticed and suspect that the quotation marks around CURRENT_TIMESTAMP is the culprit here. Just to sure, is the default value created directly in the database and not via the app? (I believe the app dictates "use current date/time" with a special value 'date-created' rather than the db function CURRENT_TIMESTAMP by default)

Testing with SQL queries

With quotes

chrome_5xeRFHcqKW

No quotes

chrome_6Y1ooY5SvL

@azrikahar azrikahar added the API label Mar 9, 2022
@stefan1968
Copy link
Author

It's created via the APP/UI, when setting the default value. I use the expression now() when creating the field. Which then turns into CURRENT_TIMESTAMP

Here is a link to the schema.

https://drive.google.com/drive/folders/1qw_iPfCBhfm9JVvfUxYgmUtxf0TFo8xJ?usp=sharing

@azrikahar
Copy link
Contributor

Thanks for the snapshot and clarification. I've just tried it locally and I can reproduce the same issue:

WindowsTerminal_1TGAp3SWvp

This is because of the default value CURRENT_TIMESTAMP is being set as string as expected:

Code_kizIs8pHP0

However, I did try to trace and see what's going wrong here and I've found this particular code where we are ensuring now() gets interpreted correctly:

if (field.schema?.default_value !== undefined) {
if (typeof field.schema.default_value === 'string' && field.schema.default_value.toLowerCase() === 'now()') {
column.defaultTo(this.knex.fn.now());
} else if (

Using this knowledge, I was able to make your schema snapshot work by swapping CURRENT_TIMESTAMP to now() manually:

WindowsTerminal_iS6EAUGvnG

So perhaps you can use this workaround for now while we find a better fix for it 👍

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

Successfully merging a pull request may close this issue.

3 participants