-
-
Notifications
You must be signed in to change notification settings - Fork 8
Horizon: Rewrite database structure and migrations #92
Description
God, the database structure is a mess. Our relations are broken, etc.
Who's idea was it to use the codename of milestones as IDs?
Ow...
This issue isn't only about cleaning up our database structure and migrations. We'll also provide factories for all relevant models and seeders for anyone who wants to set up a local copy of ChangeWindows.
The new rules
For this project, a few rules have been set up. Some of these are common sense, some of these are Laravel guidelines and some of these are unique to ChangeWindows itself. These are just the rules that the current database wouldn't pass.
- Every database table that isn't a pivot table has a unique numerical auto-incrimenting id, no exceptions. A pivot table uses a combination off the 2 or more foreign keys that make each line unique.
- Every table has Laravel's auto-generated created_at and updated_at fields.
- Any relation-field has the
_id-suffix. - Pivot tables are named in a
parent_child-pattern, not alphabetically as is enforced by Laravel. E.g. a platform has channels, thus its pivot table is namedplatform_channelsand notchannel_platformsas Laravel defaults towards. - All relations are defined with their constraints.
- No fields should be added behind Laravel's
created_atandupdated_atfields, with the exception of Laravel'sdeleted_atfield in case support for soft deleting is required. - Any table that has url-facing data has a slug field whom's value is set as the route key name to generate readable urls. E.g. platforms should have a slug, releases however shouldn't.
The only exception to these rules is the Buildfeed-table.
What this issue fixes
Right from the start, this means that a lot of things need to be fixed. The items that start with a (6) are new since version 6. Here is a list of all the fixes that Horizon applies:
- Renames the
ability_rolestable torole_abilities. - Adds proper constraint from
role_abilitiesto roles. - Adds proper constraint from
role_abilitiesto abilities. - Renames
abilities.labeltoabilities.descriptionto properly reflect the function of the field. - Renames
roles.labeltoroles.descriptionto properly reflect the function of the field. - Removes the
roles.rank-field which is a leftover of ChangeWindows 5.1. - Reorganizes the entire
users-table field order. - Adds a
users.slugfield to store the slug for a user account based onname. - Adds proper constraint from roles to users.
- (6) Renames the
channel_platformstable toplatform_channels. - Adds
milestones.canonical_versionwhich contains anXXYY-formatted version number for any milestone. - Renames
milestones.osnametomilestones.product_nameto improve clearity of what the fields contains. - Renames
milestones.previewtomilestones.start_previewto better reflect the order of this field. - Renames
milestones.publictomilestones.start_publicto better reflect the order of this field. - Renames
milestones.mainEoltomilestones.start_extendedto better reflect the order of this field. - Renames
milestones.mainXoltomilestones.start_ltsto better reflect the order of this field. - Renames
milestones.ltsEoltomilestones.end_ltsto better reflect the order of this field. - Adds a
milestones.slugfield to store the slug for a milestone based oncodename. - Renames
releases-table toflights. - Renames
releases.milestonetoflights.milestone_idand changes type tobigint(20)to follow foreign key convention. - Renames
releases.ringtoflights.channel_idto follow foreign key convention. - Renames
releases.platformtoflights.platform_idto follow foreign key convention. - Adds
flights.user_idto track user. - Removes the
role_user-table. - Removes the
patreons-table. - Removes the
changelogs-table. - Removes the
vnext-table.