The design and thinking of the table structure of the uploaded resource file, and the reconstruction of the overall process

选题表 plan 中添加字段:material_asset_id,迁移表 plan_asset 中的关联关系至 material_asset_id,遍历选题记录,在选题资源表中查询是否存在对应选题的资源记录,如果存在,则将资源主键ID更新至 material_asset_id,迁移后的结果,符合预期
1. The current table design (the relationship between the topic selection and the resource), the field: plan_id indicates which topic selection ID the record belongs to, as shown in Figure 1
现阶段的表设计(选题与资源的关联),字段:plan_id 表示记录属于哪一个选题ID
Figure 1
2. In the editing topic page, 2 resource files are uploaded, as shown in Figure 2
在编辑选题页面,上传了 2 个资源文件
Figure 2
3. After saving the topic, open the resource table and data records, as shown in Figure 3
保存选题之后,打开资源表,数据记录
Figure 3
4. When designing the table structure before, the resource table is only used for the resource file under the topic selection, but now, in other pages (base settings, user settings), the resource file needs to be uploaded, as shown in Figure 4
之前设计表结构时,资源表仅用于选题下的资源文件,但是,现在在其他页面(基地设置、用户设置)中,也需要上传资源文件
Figure 4
Therefore, it is decided to rename the table name, plan_asset is asset, and delete the field: plan_id. Add the field of the resource ID of the material in the topic table plan, multiple uses, and the number is separated: material_asset_id, after refactoring, like in step 3, the resource table has been added 2 For records, the primary key IDs are: 13 and 14, then the fields in the topic table plan: material_asset_id are: 13, 14, so as to determine the relationship between the topic and the resource. 6. Add fields in the topic table plan: material_asset_id, the correlation relationship in the migration table plan_asset to material_asset_id, traverse the topic selection record, and check whether there is a resource record corresponding to the topic in the topic selection resource table.
选题表 plan 中添加字段:material_asset_id,迁移表 plan_asset 中的关联关系至 material_asset_id,遍历选题记录,在选题资源表中查询是否存在对应选题的资源记录,如果存在,则将资源主键ID更新至 material_asset_id,迁移后的结果,符合预期
Figure 5


PS E:\wwwroot\pcs-api> ./yii migrate
Yii Migration Tool (based on Yii v2.0.15.1)

Total 1 new migration to be applied:
        m191016_022618_add_material_asset_id_to_plan

Apply the above migration? (yes|no) [no]:yes
*** applying m191016_022618_add_material_asset_id_to_plan
    > add column material_asset_id string(1024) NOT NULL DEFAULT '' COMMENT '素材的资源ID,多个用,号隔开' AFTER `opinion
` to table {{%plan}} ... done (time: 0.081s)
    > update {{%plan}} ... done (time: 0.005s)
    > update {{%plan}} ... done (time: 0.002s)
*** applied m191016_022618_add_material_asset_id_to_plan (time: 0.112s)


1 migration was applied.

Migrated up successfully.


2 13
3 14,15,16,17,18


7. After the relationship between the topic selection and the resource is migrated, rename the table name, plan_asset is asset, delete field: plan_id. Subsequent Asset tables are the public tables of the resource files of all data, and the correlation relationship is maintained by themselves in their respective data tables. as shown in Figure 6
选题与资源的关联关系迁移完毕后,则重命名表名,plan_asset 为 asset,删除字段:plan_id。后续 asset 表做为所有数据的资源文件的公共表,关联关系在各自的数据表中自行维护
Figure 6


PS E:\wwwroot\pcs-api> ./yii migrate
Yii Migration Tool (based on Yii v2.0.15.1)

Total 1 new migration to be applied:
        m191016_070338_rename_plan_asset_to_asset

Apply the above migration? (yes|no) [no]:yes
*** applying m191016_070338_rename_plan_asset_to_asset
    > rename table {{%plan_asset}} to {{%asset}} ... done (time: 0.023s)
    > drop comment from table {{%asset}} ... done (time: 0.011s)
    > add comment on table {{%asset}} ... done (time: 0.009s)
    > drop column plan_id from table {{%asset}} ... done (time: 0.064s)
*** applied m191016_070338_rename_plan_asset_to_asset (time: 0.120s)


1 migration was applied.

Migrated up successfully.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.