discourse/lib/tasks
Osama Sayegh 3cadd6769e
FEATURE: Theme settings migrations (#24071)
This commit introduces a new feature that allows theme developers to manage the transformation of theme settings over time. Similar to Rails migrations, the theme settings migration system enables developers to write and execute migrations for theme settings, ensuring a smooth transition when changes are required in the format or structure of setting values.

Example use cases for the theme settings migration system:

1. Renaming a theme setting.

2. Changing the data type of a theme setting (e.g., transforming a string setting containing comma-separated values into a proper list setting).

3. Altering the format of data stored in a theme setting.

All of these use cases and more are now possible while preserving theme setting values for sites that have already modified their theme settings.

Usage:

1. Create a top-level directory called `migrations` in your theme/component, and then within the `migrations` directory create another directory called `settings`.

2. Inside the `migrations/settings` directory, create a JavaScript file using the format `XXXX-some-name.js`, where `XXXX` is a unique 4-digit number, and `some-name` is a descriptor of your choice that describes the migration.

3. Within the JavaScript file, define and export (as the default) a function called `migrate`. This function will receive a `Map` object and must also return a `Map` object (it's acceptable to return the same `Map` object that the function received).

4. The `Map` object received by the `migrate` function will include settings that have been overridden or changed by site administrators. Settings that have never been changed from the default will not be included.

5. The keys and values contained in the `Map` object that the `migrate` function returns will replace all the currently changed settings of the theme.

6. Migrations are executed in numerical order based on the XXXX segment in the migration filenames. For instance, `0001-some-migration.js` will be executed before `0002-another-migration.js`.

Here's a complete example migration script that renames a setting from `setting_with_old_name` to `setting_with_new_name`:

```js
// File name: 0001-rename-setting.js

export default function migrate(settings) {
  if (settings.has("setting_with_old_name")) {
    settings.set("setting_with_new_name", settings.get("setting_with_old_name"));
  }
  return settings;
}
```

Internal topic: t/109980
2023-11-02 08:10:15 +03:00
..
add_topic_to_quotes.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
admin.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
annotate.rake FEATURE: Create legal topics for set company name (#21620) 2023-05-24 23:05:36 +03:00
api.rake FEATURE: Hash API keys in the database (#8438) 2019-12-12 11:45:00 +00:00
assets.rake DEV: Simplify sprockets configuration (#24111) 2023-10-26 17:29:53 +01:00
auto_annotate_models.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
autospec.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
avatars.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
backfill.thor DEV: Format .thor files (#23059) 2023-08-10 13:59:13 +02:00
categories.rake FIX: Update category tag stats with new or deleted (#21531) 2023-05-18 12:46:44 +03:00
cdn.rake DEV: Prefer \A and \z over ^ and $ in regexes (#19936) 2023-01-20 12:52:49 -06:00
db.rake FIX: Ensure JS transpiler is available for multisite-migrate (#24136) 2023-10-27 09:59:41 +01:00
destroy.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
dev.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
docker.rake DEV: Support RUN_SYSTEM_TESTS and SINGLE_PLUGIN in docker test task (#24040) 2023-10-23 07:41:21 +08:00
documentation.rake DEV: Restore the documentation format in system tests (#21471) 2023-05-12 11:13:52 +02:00
emails.rake FIX: improve mailman email parsing (#21627) 2023-05-19 10:33:48 +02:00
emoji.rake DEV: Update minitest to 5.19.0 (#22821) 2023-07-27 12:18:40 +02:00
export.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
groups.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
hashtags.rake DEV: Capture output in hashtags spec (#20773) 2023-03-23 11:47:14 +10:00
i18n.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
images.rake DEV: Upgrade to Rails 7 2022-04-28 11:51:03 +02:00
import.rake DEV: Create missing user profiles in "import:ensure_consistency" rake task 2023-08-09 20:56:14 +02:00
incoming_emails.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
integration.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
javascript.rake DEV: Do not auto-generate plugin routes for admin experimental sidebar (#24211) 2023-11-02 12:13:20 +10:00
log.rake FIX: whoops, linting 2020-09-03 12:10:11 +01:00
maxminddb.rake DEV: Avoid constant redefinition warnings in specs (#23241) 2023-08-24 23:16:32 +02:00
plugin.rake Remove discourse-canned-replies from official list (#22932) 2023-08-02 12:48:20 +01:00
populate.rake DEV: Convert admin-incoming-email modal to component-based API (#22701) 2023-07-20 16:31:20 -05:00
populate.thor DEV: Format .thor files (#23059) 2023-08-10 13:59:13 +02:00
posts.rake DEV: Replace #pluck_first freedom patch with AR #pick in core (#19893) 2023-02-13 12:39:45 +08:00
profile.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
qunit.rake DEV: Write ember exam execution file for plugin qunit in CI (#23877) 2023-10-10 16:29:28 +01:00
redis.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
release_note.rake DEV: Add link to PR when generating release notes 2023-09-12 09:26:46 +02:00
revisions.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
rspec.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
s3.rake FEATURE: allow S3 ACLs to be disabled (#21769) 2023-06-06 15:47:40 +10:00
scheduler.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
search.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
site_settings.rake DEV: Add rake command to help detect dead settings (#23300) 2023-08-29 09:42:52 -06:00
site.rake FEATURE: Add dark mode option for category backgrounds (#24003) 2023-10-20 12:48:06 +00:00
smoke_test.rake DEV: Drop /theme-qunit from smoke test (#23562) 2023-09-13 16:14:27 +01:00
svg_icons.rake DEV: Enable unless cops 2023-02-21 10:30:48 +01:00
svg_sprites.rake DEV: Store theme sprites in the DB (#20501) 2023-03-14 13:11:45 -05:00
tags.rake DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
themes.rake FEATURE: Theme settings migrations (#24071) 2023-11-02 08:10:15 +03:00
topics.rake FEATURE: do not bump topics when retroactively closing (#23115) 2023-08-16 11:20:47 +10:00
turbo.rake DEV: Fix bin/turbo_rspec runtime recording (#20407) 2023-02-23 07:47:11 +10:00
typepad.thor DEV: Format .thor files (#23059) 2023-08-10 13:59:13 +02:00
uploads.rake FEATURE: Add dark mode option for category backgrounds (#24003) 2023-10-20 12:48:06 +00:00
users.rake DEV: Add task to anonymize user data (#20522) 2023-10-03 16:59:43 +08:00
version_bump.rake DEV: Do not squash commits in version_bump:stage_security_fixes (#23547) 2023-09-12 18:00:42 +01:00