Closed evertonchapani closed 4 months ago
Hi @evertonchapani,
This use case is similar to issue #44. You can also use hooks to modify the data loaded from files.
You could have a separate directus-sync.config.js
for each target environment. For example, directus-sync.config.env-1.js
and directus-sync.config.env-2.js
, both of which extend a base configuration directus-sync.config.base.js
.
// ./directus-sync.config.env-1.js
module.exports = {
extends: ['./directus-sync.config.base.js'],
directusUrl: 'https://directus-1.example.com',
directusToken: 'my-directus-1-token',
hooks: {
folders: { onLoad: () => [] }, // This will "hide" the 'folders' collection
},
};
// ./directus-sync.config.env-2.js
module.exports = {
extends: ['./directus-sync.config.base.js'],
directusUrl: 'https://directus-2.example.com',
directusToken: 'my-directus-2-token',
hooks: {
presets: { onLoad: () => [] }, // This will "hide" the 'presets' collection
},
};
This setup hides the folders
collection in the first environment and the presets
collection in the second one.
Hi @EdouardDem. Thanks for the fast response! I got you, but I think I used the wrong term here. When I say collections I mean the data models, and since we have only a set of options for hooks and none of them mention the data models I don't think I can make it work with hooks. Or am I missing something here?
@evertonchapani Apologies for the misunderstanding. Unfortunately, it is currently not possible to modify the snapshot during the push process. However, this is an interesting feature suggestion. I could implement a hook that allows users to alter the snapshot before saving it and also after loading it from JSON files. I will include this in the roadmap.
Wonderful! Thanks a lot!
Do you happen to know any other ways that I can automate the setup for this use case while this feature is not ready on Directus Sync?
@evertonchapani Sorry for the late response.
You could clone and edit the snapshots manually and store them into separate folder. Then, each configuration can specify a different folder:
// ./directus-sync.config.env-1.js
module.exports = {
extends: ['./directus-sync.config.base.js'],
directusUrl: 'https://directus-1.example.com',
directusToken: 'my-directus-1-token',
snapshotPath: 'snapshot-1'
};
// ./directus-sync.config.env-2.js
module.exports = {
extends: ['./directus-sync.config.base.js'],
directusUrl: 'https://directus-2.example.com',
directusToken: 'my-directus-2-token',
snapshotPath: 'snapshot-2'
};
If you want to save the snaphot in a single file, you can use the split
option.
No problem! I'll give it a try, thanks!
@evertonchapani I've just published a new version with features you might be interested in:
You can check the release note: https://github.com/tractr/directus-sync/releases/tag/directus-sync%401.5.2
Perfect, thanks!
Is it possible to maintain environment-specific collections while pushing the schema? For instance:
Base collections:
Specific Environment 1:
Specific Environment 2:
My goal is to apply changes to collection 1 and 2, and track new base collections as well, without touching in the specific environment collections. Is it possible? if not, take this as a suggestion (I know it's really hard to achieve, considering the conflicts that can happen with it). Thanks!