bcc-code / directus-schema-sync

The better way to sync your Directus schema and data between environments
Apache License 2.0
90 stars 4 forks source link

Improve sync hooks #27

Closed adelinn closed 4 months ago

adelinn commented 4 months ago

This PR adds import and diff result modifier functions along the existing export modifier function. Those are used to modify the input and the diff, resulted from comparing the stored schema with the current one, before they are used.

The export and import modifiers sets the has_auto_increment property to true to fields which have default_value following this format: nextval('"+field_collection+"_"+field_name+"_seq'::regclass)

The diff modifier bypasses Directus' apply and applies the diff through a raw SQL query for diffs that change the current default value of fields to one of this format nextval('"+field_collection+"_"+field_name+"_seq'::regclass). It also modifies the diffs that create new integer type fields containing a string starting with nextval as the default_value by casting the default_value string to a Knex.raw() object before letting Directus apply it.

This PR also disables all those modifier functions by default unless SCHEMA_SYNC_HOOKS_ENABLED environment variable is set to true.

u12206050 commented 4 months ago

Thank you for your effort in this, however looking at the code, I seems this is a problem in general with the Directus schema import, did you check/open an issue on Directus and see maybe about making PR on there?

Otherwise this library starts becoming the work around and patching of Directus, instead of fixing issues like these in the core.

You are welcome to attach this PR as a reference to the Directus Issue.

adelinn commented 4 months ago

You are right. I'll close this PR then.