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

Introspect default constraint name #5662

Merged
merged 2 commits into from
Sep 18, 2022

Conversation

morozov
Copy link
Member

@morozov morozov commented Sep 10, 2022

The current approach to managing default column values on SQL Server has a few significant downsides:

  1. The schema manager manages the schema with the assumption that the foreign key constraints are named in a certain way:
    private function generateDefaultConstraintName(string $table, string $column): string
    {
    return 'DF_' . $this->generateIdentifierName($table) . '_' . $this->generateIdentifierName($column);
    }

    It makes it unable to manage the schema that was not created by the DBAL.
  2. In order to maintain the naming of the default constraints with the above convention, the schema manager has to rename the affected default constraints if the table or the column that it belongs to is renamed:
    1. Renaming column:
      // Recreate default constraint with new column name if necessary (for future reference).
    2. Renaming table:
      /**
      * Rename table's default constraints names
      * to match the new table name.
      * This is necessary to ensure that the default
      * constraints can be referenced in future table
      * alterations as the table name is encoded in
      * default constraints' names.
      */

The proposed approach eliminates the dependency on the naming convention and instead introspects the default constraints.

@morozov morozov force-pushed the sql-server-default-constraint-name branch from 7650f61 to fe0dd02 Compare September 11, 2022 18:49
@morozov morozov force-pushed the sql-server-default-constraint-name branch from fe0dd02 to c8d2c3d Compare September 11, 2022 18:58
@morozov morozov merged commit 0e15462 into doctrine:4.0.x Sep 18, 2022
@morozov morozov deleted the sql-server-default-constraint-name branch September 18, 2022 14:14
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants