数据迁移:将 SQL 从 Strapi v3 迁移到 v4
¥Data migration:Migrate SQL from Strapi v3 to v4
Strapi 的数据库层已在 Strapi v4
中完全重写。本文档旨在通过比较 v3
和 v4
表和列名称、数据结构和关系,重点介绍 Strapi v4
中引入的影响 SQL 数据库的重大更改。
¥The database layer of Strapi has been fully rewritten in Strapi v4
. This documentation is designed to highlight the breaking changes introduced in Strapi v4
that impact SQL databases, by comparing v3
and v4
table and column names, data structures and relations.
更改可以是 global(影响任何表)或更有限的范围,仅影响 具体表格 或某些 Strapi 插件。
¥Changes can be global (impacting any table) or more limited in scope, impacting only specific tables or some Strapi plugins.
v3 与 v4 SQL 关系速查表 旨在帮助你了解 Strapi v3
和 Strapi v4
之间模型架构和实体关系图的差异。
¥The v3 vs. v4 SQL relations cheatsheet is designed to help you understand the differences in model schemas and entity relationship diagrams between Strapi v3
and Strapi v4
.
数据迁移脚本 目前正在进行 alpha/beta 测试。请随时在 专门的论坛主题 中分享反馈。
¥Data migration scripts are currently in alpha/beta testing. Please feel free to share feedback in the dedicated forum thread.
全局变化
¥Global changes
列大小写和时间戳列的更改可能会影响所有表。
¥Changes in column casing and timestamps columns can affect all tables.
列名大小写
¥Column name casing
在 Strapi v3
中,列名称可以具有不同的大小写(例如 PascalCase
、camelCase
和 snake_case
)。
¥In Strapi v3
column names can have different casings (e.g. PascalCase
, camelCase
, and snake_case
).
在 Strapi v4 中,每个列名称都应使用 snake_case
。
¥In Strapi v4, every column name should use snake_case
.
要迁移到 Strapi v4
,请确保所有列名称都使用 snake_case
。模型模式中另一个外壳中定义的属性在与数据库层通信时,其名称将自动转换为 snake_case
。
¥To migrate to Strapi v4
, make sure all column names use snake_case
. Attributes defined in another casing in the model schema will have their name automatically transformed to snake_case
when communicating with the database layer.
时间戳列
¥Timestamps columns
时间戳列指的是 created_at
和 updated_at
列。
¥Timestamps columns refer to the created_at
and updated_at
columns.
在 Strapi v3
中,时间戳列直接由数据库层赋予默认值(即 CURRENT_TIMESTAMP
)。
¥In Strapi v3
, timestamps columns are given a default value (i.e. CURRENT_TIMESTAMP
) directly by the database layer.
在 Strapi v4
中,无法重命名或禁用时间戳列。
¥In Strapi v4
, timestamps columns can't be renamed or disabled.
要迁移到 Strapi v4
,请将具有自定义列名称的时间戳迁移到 created_at
和 updated_at
字段,并从表结构中删除默认值。
¥To migrate to Strapi v4
, migrate timestamps with custom column names to the created_at
and updated_at
fields, and remove the default value from the table structure.
影响 Strapi 内置表格的更改
¥Changes impacting Strapi built-in tables
Strapi 内置表格在 v3
和 v4
中具有不同的名称,并且 Strapi v4 引入了新表格(由 ✨ 表情符号表示):
¥Strapi built-in tables have a different name in v3
and v4
, and Strapi v4 introduces new tables (indicated by the ✨ emoji):
Strapi v3 中的表名称 | Strapi v4 中的表名称 |
---|---|
strapi_permission | admin_permissions (见 管理员权限) |
strapi_role | admin_roles |
strapi_administrator | admin_users |
strapi_users_roles | admin_users_roles_links |
strapi_webhooks | strapi_webhooks |
core_store | strapi_core_store_settings (见 核心店) |
(不适用) | ✨ admin_permissions_role_link (见 管理员权限) |
(不适用) | ✨ strapi_migrations |
(不适用) | ✨ strapi_api_tokens |
(不适用) | ✨ strapi_database_schema |
管理员权限
¥Admin permissions
Strapi v3
中使用的 strapi_permission
表在 Strapi v4
中被命名为 admin_permissions
,并且会进行以下其他更改:
¥The strapi_permission
table used in Strapi v3
is named admin_permissions
in Strapi v4
, and is subject to the following other changes:
Strapi
v3
和 Strapiv4
中的表结构不同:¥The table structure is different in Strapi
v3
and Strapiv4
:
Strapi
v4
中的角色关系在名为admin_permissions_role_links
的连接表中处理。¥The role relation in Strapi
v4
is handled in a join table namedadmin_permissions_role_links
.已为 Strapi v3 的
created_by_id
和updated_by_id
列创建了新索引,名称如下:¥New indexes have been created for the
created_by_id
andupdated_by_id
columns of Strapi v3, with the following names:Strapi v3 中的列名称 Strapi v4 中的索引名称 created_by_id
admin_permissions_created_by_id_fk
updated_by_id
admin_permissions_updated_by_id_fk
核心店
¥Core store
Strapi v3
中使用的 core_store
表在 Strapi v4
中被命名为 strapi_core_store_settings
。
¥The core_store
table used in Strapi v3
is named strapi_core_store_settings
in Strapi v4
.
核心存储表的结构保持不变,但模型定义和内容管理器配置已更改。
¥The structure of the core store table remains untouched, but model definitions and content manager configurations have changed.
模型定义
¥Model definitions
所有以 model_def_
开头的行都已被删除,不再需要。
¥All the rows that begin with model_def_
have been dropped and are no longer required.
内容管理器配置
¥Content manager configurations
以 plugin_content_manager_configuration_content_types
开头的所有行均已更改,以匹配新的唯一标识符 (UID) 并反映 表名更改。这些更改包括 key
列的后缀和 value
列中的 uid
字段。
¥All the rows that begin with plugin_content_manager_configuration_content_types
have been changed to match new unique identifiers (UIDs) and reflect table names changes. These changes include both the suffix of the key
column and the uid
field in the value
column.
除了已重命名的所有内容类型(参见 表名更改)之外,以下 UID 也已更改:
¥In addition to all the content-types that have been renamed (see table names changes), the following UIDs have changed:
Strapi v3 中的 UID | Strapi v4 中的 UID |
---|---|
application | api |
plugins | plugin |
权限映射
¥Permissions mapping
下表列出了 Strapi v3 和 Strapi v4 之间所有权限的映射:
¥The following tables list the mapping of all permissions between Strapi v3 and Strapi v4:
Permission mapping for an example "restaurant" API:
Strapi v3 型 | Strapi v3 控制器 | Strapi v3 动作 | Strapi v4 动作 |
---|---|---|---|
application | restaurant | count | (已删除) |
application | restaurant | create | api::restaurant.restaurant.create |
application | restaurant | delete | api::restaurant.restaurant.delete |
application | restaurant | find | api::restaurant.restaurant.find |
application | restaurant | findone | api::restaurant.restaurant.findOne |
application | restaurant | update | api::restaurant.restaurant.update |
application | restaurant | createlocalization | api::restaurant.restaurant.createLocalization |
Permission mapping for the Users & Permission plugin:
Strapi v3 型 | Strapi v3 控制器 | Strapi v3 动作 | Strapi v4 动作 |
---|---|---|---|
users-permissions | auth | callback | 插件::users-permissions.auth.callback |
users-permissions | auth | connect | 插件::users-permissions.auth.connect |
users-permissions | auth | emailconfirmation | 插件::users-permissions.auth.emailConfirmation |
users-permissions | auth | forgotpassword | 插件::users-permissions.auth.forgotPassword |
users-permissions | auth | register | 插件::users-permissions.auth.register |
users-permissions | auth | resetpassword | 插件::users-permissions.auth.resetPassword |
users-permissions | auth | sendemailconfirmation | 插件::users-permissions.auth.sendEmailConfirmation |
users-permissions | user | count | 插件::users-permissions.user.count |
users-permissions | user | create | 插件::users-permissions.user.create |
users-permissions | user | destroy | 插件::users-permissions.user.destroy |
users-permissions | user | destroyall | (已删除) |
users-permissions | user | find | 插件::users-permissions.user.find |
users-permissions | user | findone | 插件::users-permissions.user.findOne |
users-permissions | user | me | 插件::用户权限.user.me |
users-permissions | user | update | 插件::用户权限.user.update |
users-permissions | userspermissions | getrole | 插件::users-permissions.role.getRole |
users-permissions | userspermissions | getroles | 插件::users-permissions.role.getRoles |
users-permissions | userspermissions | createrole | 插件::users-permissions.role.createRole |
users-permissions | userspermissions | deleterole | 插件::users-permissions.role.deleteRole |
users-permissions | userspermissions | updaterole | 插件::users-permissions.role.updateRole |
users-permissions | userspermissions | getpermissions | 插件::users-permissions.permissions.getPermissions |
users-permissions | userspermissions | getadvancedsettings | (已删除) |
users-permissions | userspermissions | customroute | (已删除) |
users-permissions | userspermissions | getemailtemplate | (已删除) |
users-permissions | userspermissions | getpolicies | (已删除) |
users-permissions | userspermissions | getproviders | (已删除) |
users-permissions | userspermissions | getroutes | (已删除) |
users-permissions | userspermissions | index | (已删除) |
users-permissions | userspermissions | searchusers | (已删除) |
users-permissions | userspermissions | updateadvancedsettings | (已删除) |
users-permissions | userspermissions | updateemailtemplate | (已删除) |
users-permissions | userspermissions | updateproviders | (已删除) |
Permission mapping for the i18n plugin:
Strapi v3 型 | Strapi v3 控制器 | Strapi v3 动作 | Strapi v4 动作 |
---|---|---|---|
国际化 | content-types | getnonlocalizedattributes | (已删除) |
国际化 | 等区域设置 | listisolocales | (已删除) |
国际化 | locales | createlocale | (已删除) |
国际化 | locales | deletelocale | (已删除) |
国际化 | locales | listlocales | 插件::i18n.locales.listLocales |
国际化 | locales | updatelocale | (已删除) |
Permission mapping for the Content-Type Builder:
Strapi v3 型 | Strapi v3 控制器 | Strapi v3 动作 | Strapi v4 动作 |
---|---|---|---|
内容类型构建器 | builder | getreservednames | (已删除) |
内容类型构建器 | componentcategories | deletecategory | (已删除) |
内容类型构建器 | componentcategories | editcategory | (已删除) |
内容类型构建器 | components | createcomponent | (已删除) |
内容类型构建器 | components | deletecomponent | (已删除) |
内容类型构建器 | components | getcomponent | 插件::content-type-builder.components.getComponent |
内容类型构建器 | components | getcomponents | 插件::content-type-builder.components.getComponents |
内容类型构建器 | components | updatecomponent | (已删除) |
内容类型构建器 | connections | getconnections | (已删除) |
内容类型构建器 | contenttypes | createcontenttype | (已删除) |
内容类型构建器 | contenttypes | deletecontenttype | (已删除) |
内容类型构建器 | contenttypes | getcontenttype | 插件::content-type-builder.content-types.getContentType |
内容类型构建器 | contenttypes | getcontenttypes | 插件::content-type-builder.content-types.getContentTypes |
内容类型构建器 | contenttypes | updatecontenttype | (已删除) |
Permission mapping for the Upload plugin:
Strapi v3 型 | Strapi v3 控制器 | Strapi v3 动作 | Strapi v4 动作 |
---|---|---|---|
upload | upload | count | 插件::upload.content-api.count |
upload | upload | destroy | 插件::upload.content-api.destroy |
upload | upload | find | 插件::upload.content-api.find |
upload | upload | findone | 插件::upload.content-api.findOne |
upload | upload | getsettings | (已删除) |
upload | upload | search | (已删除) |
upload | upload | updatesettings | (已删除) |
upload | upload | upload | 插件::upload.content-api.upload |
Permission mapping for the Email plugin:
Strapi v3 型 | Strapi v3 控制器 | Strapi v3 动作 | Strapi v4 动作 |
---|---|---|---|
getsettings | (已删除) | ||
send | 插件::email.email.send | ||
test | (已删除) |
Permission mapping for the Content Manager and the Documentation plugin:
所有权限都被删除。
¥All permissions were deleted.
影响 Strapi 插件的变化
¥Changes impacting Strapi plugins
Strapi v4
引入了重大更改,这些更改影响 用户和权限、上传 和 国际化(i18n) 插件使用的表名称、列名称和数据库结构。
¥Strapi v4
introduces breaking changes that impact the table names, column names and database structures used by the Users & Permissions, Upload and Internationalization (i18n) plugins.
用户和权限插件
¥Users and Permissions plugin
用户和权限插件 使用的表和数据库结构在 Strapi v3
和 Strapi v4
中有所不同:
¥The tables and database structure used by the Users & Permissions plugin are different in Strapi v3
and Strapi v4
:
Strapi v3:
Strapi v4:
启用的权限
¥Enabled permissions
在 Strapi v3 中,权限始终存在于表中,并且针对每个角色都是重复的。如果权限 "A" 的 enabled
列值设置为 1
(true
),则为角色 "X" 设置权限 "A"。
¥In Strapi v3, permissions are always present in the table and are duplicated for each role. A permission "A" is set for a role "X" if permission "A" has the enabled
column value set to 1
(true
).
在 Strapi v4 中,数据库表中不存在未为任何角色启用的权限(即不再有 enabled
列)。如果存在以下情况,则为角色 "X" 设置权限 "A":
¥In Strapi v4, permissions that aren’t enabled for any role are not present in the database table (i.e. there is no more enabled
column). A permission "A" is set for a role "X" if there is:
表行中的权限 "A"
¥a permission "A" in the table rows
以及连接表中将角色 "X" 链接到权限 "A" 的行。
¥and a row linking the role "X" to the permission "A" in the join table.
权限列
¥Permissions columns
在 Strapi v3 中,权限由 3 列定义:type
、controller
和 action
。
¥In Strapi v3, permissions are defined by 3 columns:type
, controller
, and action
.
在 Strapi v4 中,type
、controller
和 action
列被名为 action
的单个列取代,聚合如下:action = transform(type).controller.action
。
¥In Strapi v4, the type
, controller
and action
columns are replaced by a single column named action
, aggregated like the following:action = transform(type).controller.action
.
有关更多信息和具体示例,你可以比较 Strapi v3 users-permissions_permission
和 Strapi v4 up_permissions
表中相同权限的输出。
¥For more information and specific examples, you can compare the output of the same permission in Strapi v3 users-permissions_permission
and Strapi v4 up_permissions
tables.
上传插件
¥Upload plugin
在 Strapi v3 中,与文件内容类型关联的多态表被命名为 upload_file_morph
,并且具有 id
和 upload_file_id
属性。
¥In Strapi v3, the polymorphic table associated to the file content-type is named upload_file_morph
and has both an id
and an upload_file_id
attribute.
在 Strapi v4 中,上传插件 的数据结构发生了以下变化:
¥In Strapi v4, the data structure of the Upload plugin is subject to the following changes:
该多态性表被命名为
files_related_morphs
。该名称包括related
,因为它涉及模型架构中定义的文件的related
属性。¥The polymorphic table is named
files_related_morphs
. The name includesrelated
since it concerns the file’srelated
attribute defined in the model schema.id
和upload_file_id
列不存在。¥The
id
andupload_file_id
columns do not exist.添加新列
file_id
,作为指向files.id
的外键。¥A new column
file_id
is added, as a foreign key pointing tofiles.id
.为
file_id
列创建索引,作为files_related_morph_fk
。¥An index is created for the
file_id
column, asfiles_related_morph_fk
.
国际化 (i18n) 插件
¥Internationalization (i18n) plugin
在 Strapi v4 中,国际化(i18n) 插件使用的本地化表遵循 循环多对多关系迁移,并从 entities__localizations
重命名为 entities_localizations_links
。
¥In Strapi v4, localization tables used by the Internationalization (i18n) plugin follow the circular many-to-many relationships migration and are renamed from entities__localizations
to entities_localizations_links
.