Skip to content

Execute FK queries at the end#59

Open
WilliamFalci wants to merge 2 commits into
aspiers:masterfrom
WilliamFalci:master
Open

Execute FK queries at the end#59
WilliamFalci wants to merge 2 commits into
aspiers:masterfrom
WilliamFalci:master

Conversation

@WilliamFalci
Copy link
Copy Markdown

Those changes move the FK's queries outside the creation queries and go to execute all them at the end of all other queries

This change will execute FK's queries outside all creation queries and at end of everything
This change will delete the creation of FK inside the Creation Table's queries and will move all outside at the end of all diff.
Copy link
Copy Markdown
Collaborator

@357r4bd 357r4bd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, please do the following to proceed:

  1. squash both commits
  2. create a more informative commit message
  3. utlize the "Resolves issue xxx" phrasing GH can use to link to the issue describing what this fixes
  4. address comments in the code

Thank you, looking forward to your changes.

Comment thread lib/MySQL/Diff/Table.pm
my @_lines = @{$self->{lines}};

for my $i (0 .. @_lines) {
my $lchar = unpack('A1', $_lines[$i]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment what unpack is being used for

Comment thread lib/MySQL/Diff/Table.pm
unless defined $self->{options};

@lines = grep ! m{^/\*!40\d{3} .*? \*/;}, @lines;
@lines = grep ! m{^/\*!40\d{3} .*? \*/;}, @lines;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you added training whitespace, please remove

Comment thread lib/MySQL/Diff/Table.pm

=head1 COPYRIGHT AND LICENSE


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you added 2 empty lines, please remove

Comment thread lib/MySQL/Diff/Table.pm
croak "couldn't figure out table name";
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove added white space

quaternion7 added a commit to quaternion7/mysqldiff that referenced this pull request Jan 18, 2024
I merged the PRs aspiers#59 and aspiers#65 of the main branch while also cleaning them up a bit and double checking the code. It is still untested tho.
@diegobill
Copy link
Copy Markdown

diegobill commented Dec 9, 2024

Hey @WilliamFalci ,
this version is not working, it is showing this message when executing the shell command mysql-schema-diff:

Use of uninitialized value in unpack at /usr/share/perl5/MySQL/Diff/Table.pm line 246.

and it is generating a SQL not completely sorted ("CONSTRAINT films_selected_trailer_pack_dcfafea4_fk_trailer_packs_id" should be after "CREATE TABLE trailer_packs", there is a cyclic dependency, the table trailer_packs references the table films and the table films references the table trailer_packs):

ALTER TABLE films ADD CONSTRAINT films_selected_trailer_pack_dcfafea4_fk_trailer_packs_id FOREIGN KEY (selected_trailer_pack) REFERENCES trailer_packs (id);

CREATE TABLE trailer_packs (
  id int NOT NULL AUTO_INCREMENT,
  notes longtext COLLATE utf8mb4_general_ci NOT NULL,
  film int NOT NULL,
  printid int DEFAULT NULL,
  PRIMARY KEY (id),
  KEY trailer_packs_film_3f48c68a_fk_films_code (film)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

ALTER TABLE trailer_packs ADD CONSTRAINT trailer_packs_film_3f48c68a_fk_films_code FOREIGN KEY (film) REFERENCES films (code);

The SQL above creates the error:

Failed to open the referenced table 'trailer_packs'

@WilliamFalci
Copy link
Copy Markdown
Author

@diegobill Hello! Sincerally I stopped to write in PHP many years ago and my current stack is node/typescript (primary), I remember I ended to make this: https://github.com/WilliamFalci/_mysqlDiff and when I did was working pretty good.

If you not find a solution I will try to help you to figure out the solution, but I have no effort to develop more in PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants