Ability to rename collections and fields #2711
Replies: 17 comments 36 replies
-
If you go through all the system collection field name references you should be ok:
We'll be adding a feature to automate this in an upcoming version... |
Beta Was this translation helpful? Give feedback.
-
It would be good to also include the ability to rename collections and the underlying database tables. |
Beta Was this translation helpful? Give feedback.
-
I think we need an option to disable autosave the changes until we are done designing all related fields. The autosaving is helpful for multiple developers trying to modeling, but I think it's uncommon. I'm quite curious about the reason behind autosaving the schema though. |
Beta Was this translation helpful? Give feedback.
-
Any update on enabling field renames? Also (sort of related), the ability to update a record's PK and have the change cascade across relationships? @rijkvanzanten Would make refactoring 100x simpler! |
Beta Was this translation helpful? Give feedback.
-
Hi all! This feature is extremely needed by our team given the necessity to remodel Directus fields. Based on this, we reached out to Directus support team through Driscol and asked for a quotation to get this done. Price is very limited (below $3k) and I'd like to know if anyone is interested in joining to share the bill for getting this done; TBH dont know if this message respects new ideas' rules (in that case, sorry!!) and I'd like to deep dive with all the interested people and also Directus support team! Cheers |
Beta Was this translation helpful? Give feedback.
-
I'm building a Directus instance that maps to fields in a website template, so we can easily deploy multiple websites based on Directus content, this works really well. By far, the biggest issue I've had with this so far is that I can't rename fields. Sometimes naming changes or there was a typo or another reason but then I have to delete that field and re-create it which is a super big hassle, not to mention it can only be done before content has been added since it would lead to data loss otherwise. I understand it's not so simple to rename a field because of internally named fields but I think for advanced users who are building something more than a basic content site, this is a bit of a problem. The workaround now is to write custom API calls that download content & field metadata, delete the field, re-create the field and then add the content again. This gets increasingly complex if there are relationships to this data. Just dropping my situation about it here. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
I understand the complexity of this feature but it would clearly be great if this feature could be implemented! |
Beta Was this translation helpful? Give feedback.
-
Since this has been a recurring problem, I thought I'd document how I've had to deal with it. I've had some issues with modifying schemas outside of directus where I add or remove columns using SQL and it can completely break directus's snapshot imports (e.g. when column configurations exist inside directus, but the actual column doesn't or is different). So I'd like to have a set of known safe ways to do these changes. (I'm biased towards postgres, but hopefully these apply across dbs) The main downside with this is that it's manual and you lose any field configuration and all that, but at least you keep the data. Changing a column data typeExample: converting my_table.some_column JSON to STRING (e.g. multi-dropdown to single dropdown) -- pgadmin: copy the column
alter table my_table add column tmp varchar;
-- your data type conversion could happen here
-- TODO - jsonb to csv conversion
update my_table SET tmp = some_column;
-- directus: now we can delete the column in directus
-- back to pgadmin: rename the column back to the old one
alter table deployments rename column tmp to some_column;
-- directus: go configure the field correctly Renaming a columnrenaming my_table.old_column to new_column -- pgadmin: copy the column
alter table my_table add column new_column varchar;
update my_table SET new_column = old_column;
-- directus: now we can delete the column in directus and re-configure the new field These feel a bit obvious after writing them out, but I wasn't sure about it until I did some trial and error so hopefully this will help someone. Renaming a collection... 🥸 converting jsonb to csv string (when changing data type)-- when assigning the tmp column, you can convert to csv like this
update my_table SET tmp = array_to_string(
ARRAY(select * from jsonb_array_elements_text(some_column::jsonb)),
',');
-- verify
select tmp from my_table; If you have additional ways of retaining/migrating schema changes it would be cool to document and build upon them here until we can work out a canonical way of doing it. Selfishly as well, I hope that if we can flesh out the workflows here, it would be easier for any one of us to put out a PR. I guess I'll leave some open questions:
|
Beta Was this translation helpful? Give feedback.
-
Heya! Thanks for opening this feature request! This feature request has received over 15 votes from the community. This means we'll move this feature request to the Under Review state! The Core team will schedule a meeting to review this request as soon as possible. The discussion will then be approved or denied. You may or may not be invited to join this meeting with the core team. For more information, see our Feature Request Process. |
Beta Was this translation helpful? Give feedback.
-
Very much looking forward to this one! |
Beta Was this translation helpful? Give feedback.
-
Spent an hour or so thinking through this on today's request review live stream session trying to shape this up into a proper RFC! Quite a lot to update across the database on change, so some questions around migration and adoption strategy still. In the works! Here's a live link to my our in-works RFC; i'll publish that here for archiving as well when it's done 🙂 https://directus.notion.site/Rename-Collections-Fields-3427b5e21d914e4abbdae53c48169f01?pvs=4 |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
I also want this feature, renaming collections also would be fine |
Beta Was this translation helpful? Give feedback.
-
For anyone here that is only concerned about what the Directus user sees and not names in the underlying database, you can use field name translations and collection naming translations to change the name throughout the Directus Studio. It doesn't change anything for the underlying database or the API, but it's better than nothing! |
Beta Was this translation helpful? Give feedback.
-
I would like this feature too…👀
Il giorno lun 22 gen 2024 alle 22:15 Rijk van Zanten <
***@***.***> ha scritto:
… Or is this something that would have to be done by default at some point
down the road to work?
It's really just this! If we use UUIDs in the system tables (eg in those
~20 places) instead of keys, and just store the key with the UUID in
directus_collections/fields, we only have to change it in that one place
when you want to change the key of the collection.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I always lost data when renaming them 👎 |
Beta Was this translation helpful? Give feedback.
-
Hey there !
It would be great to have the ability to rename fields of a collection.
In the meantime, what's the procedure to rename them from the database ?
directus_fields
tableAny other places I should consider checking ?
Thanks !
Beta Was this translation helpful? Give feedback.
All reactions