I'm working on a plugin, and would like to add a new Record, I already have some records, and would like to keep the data.
Is there a way to activate a new record type, without re-installing the plugin, thus loosing the other records data?
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.Sign up to join this community
The Craft website has a great article on this, you can simply use migrations following this document:
If your schema changes over the life of your plugin, you can write a migration to keep existing installations updated with the latest schema. Craft automatically checks for new migrations whenever a plugin’s version number changes.
In summary, you can create the Record and define all the attributes, then create a migration that would create the new table with those attributes. This would be done in the
safeUp() method that utilizes Craft create command:
craft()->db->createCommand()->createTable('new_table_record_name', $attributesArray, null, true);
When the plugin is updated, it will run the migrations and create the table.