Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified foreign key definition for single column fields #20

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

Steveb-p
Copy link
Contributor

@Steveb-p Steveb-p commented Jun 27, 2023

Question Answer
JIRA issue N/A
Type improvement
Target Ibexa version v4.5
BC breaks no

This PR allows definition of foreign relationship along with the field itself.

This makes it easier to spot a missing foreign key in schema.

Of course, this does not prevent the existing use of multi-column foreign keys via foreignKeys table property, in the same fashion as you can still create indexes and unique constraints.

Before

tables:
    ibexa_attribute_definition:
        indexes:
            ibexa_attribute_definition_attribute_group_idx:
                fields:
                    - attribute_group_id
        id:
            id:
                type: integer
                nullable: false
                options:
                    autoincrement: true
        fields:
            identifier:
                type: string
                nullable: false
                length: 64
            type:
                type: string
                nullable: false
                length: 32
            attribute_group_id:
                type: integer
                nullable: false
            position:
                type: integer
                nullable: false
                options:
                    default: 0
            options:
                type: json
                nullable: true
        uniqueConstraints:
            attribute_definition_identifier_idx:
                fields:
                    - identifier
        foreignKeys:
            ibexa_attribute_definition_attribute_group_fk:
                fields:
                    - attribute_group_id
                foreignTable: ibexa_attribute_group
                foreignFields:
                    - id
                options:
                    onDelete: CASCADE
                    onUpdate: CASCADE

After

tables:
    ibexa_attribute_definition:
        id:
            id:
                type: integer
                nullable: false
                options:
                    autoincrement: true
        fields:
            identifier:
                type: string
                nullable: false
                length: 64
                index:
                    name: attribute_definition_identifier_idx
                    unique: true
            type:
                type: string
                nullable: false
                length: 32
            attribute_group_id:
                type: integer
                nullable: false
                index: ibexa_attribute_definition_attribute_group_idx
                foreignKey:
                    name: ibexa_attribute_definition_attribute_group_fk
                    table: ibexa_attribute_group
                    field: id
                    options:
                        onDelete: CASCADE
                        onUpdate: CASCADE
            position:
                type: integer
                nullable: false
                options:
                    default: 0
            options:
                type: json
                nullable: true

Difference

 tables:
     ibexa_attribute_definition:
-        indexes:
-            ibexa_attribute_definition_attribute_group_idx:
-                fields:
-                    - attribute_group_id
         id:
             id:
                 type: integer
                 nullable: false
                 options:
                     autoincrement: true
         fields:
             identifier:
                 type: string
                 nullable: false
                 length: 64
+                index:
+                    name: attribute_definition_identifier_idx
+                    unique: true
             type:
                 type: string
                 nullable: false
                 length: 32
             attribute_group_id:
                 type: integer
                 nullable: false
+                index: ibexa_attribute_definition_attribute_group_idx
+                foreignKey:
+                    name: ibexa_attribute_definition_attribute_group_fk
+                    table: ibexa_attribute_group
+                    field: id
+                    options:
+                        onDelete: CASCADE
+                        onUpdate: CASCADE
             position:
                 type: integer
                 nullable: false
                 options:
                     default: 0
             options:
                 type: json
                 nullable: true
-        uniqueConstraints:
-            attribute_definition_identifier_idx:
-                fields:
-                    - identifier
-        foreignKeys:
-            ibexa_attribute_definition_attribute_group_fk:
-                fields:
-                    - attribute_group_id
-                foreignTable: ibexa_attribute_group
-                foreignFields:
-                    - id
-                options:
-                    onDelete: CASCADE
-                    onUpdate: CASCADE

Checklist:

  • Provided PR description.
  • Tested the solution manually.
  • Provided automated test coverage.
  • Checked that target branch is set correctly (main for features, the oldest supported for bugs).
  • Ran PHP CS Fixer for new PHP code (use $ composer fix-cs).
  • Asked for a review (ping @ibexa/engineering).

@Steveb-p Steveb-p changed the base branch from main to 4.5 June 27, 2023 09:11
@Steveb-p Steveb-p requested a review from a team June 27, 2023 09:36
@alongosz alongosz requested a review from a team June 27, 2023 09:38
@sonarcloud
Copy link

sonarcloud bot commented Jun 27, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Steveb-p Steveb-p requested a review from alongosz June 27, 2023 09:49
@alongosz alongosz requested a review from a team June 27, 2023 09:51
@konradoboza konradoboza requested a review from a team June 27, 2023 11:01
@webhdx webhdx requested a review from a team June 28, 2023 06:41
@Steveb-p Steveb-p merged commit dd5e0e1 into 4.5 Jun 28, 2023
13 checks passed
@Steveb-p Steveb-p deleted the foreign-key-simplified branch June 28, 2023 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants