-
Notifications
You must be signed in to change notification settings - Fork 89
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
Do not sync table that does not have a primary key #7
Comments
me too , T-T wait fix bugs |
Firstly... Every table should probably have a key :) The tool uses insert on duplicate key update to insert or update the row on the remote server. In theory of the table a unique key that wasn't the primary it would work. But I'm not sure I see the reasoning. What's the use case? Cheers
|
Yes, every table should have a primary key. |
Not every table in a relational database should have a primary key. An association / associative / relationship table is one such type of table. An associative table is a table that holds the relationship (usually many-to-many) between two tables. Having a primary key in these tables are not very useful and in some cases may add to the overhead like additional storage space for the primary key. That said... I think the overhead and time it takes to create a primary key for associative tables is probably less than trying to change this code to be able to handle tables without primary key. |
Associative tables should also have a primary key - a compound key representing all items in the association. The primary key does not have to be auto inc, DB sync will work just fine on properly modelled association tables. Cheers
|
@mrjgreen, good point. you are absolutely correct that a well structured database should have a compound key as the primary key for associative tables. With that said, I can't think of any reasons why a table cannot / should not have a primary key. besides the overhead of creating a primary key (performance, index, storage, etc) is small compared to the benefits and, in the case, the compatibility with db-sync. |
Don't ask me why but sometimes I've got some tables that do not have a primary key ;-)
Why not to sync such tables?
The table db.table does not have a primary key
#0 phar:///usr/bin/db-sync/src/Command/SyncCommand.php(178): DbSync\DbSync->sync(Object(DbSync\Table), Object(DbSync\Table), Object(DbSync\ColumnConfiguration), Object(DbSync\ColumnConfiguration))
#1 phar:///usr/bin/db-sync/src/Command/SyncCommand.php(110): DbSync\Command\SyncCommand->fire()
#2 phar:///usr/bin/db-sync/vendor/symfony/console/Command/Command.php(259): DbSync\Command\SyncCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///usr/bin/db-sync/bin/sync(75): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 phar:///usr/bin/db-sync/bin/sync(91): DbSync\Command\App->run(Object(DbSync\Command\SyncCommand))
#5 /usr/bin/db-sync(12): require('phar:///usr/bin...')
#6 {main}
#0 phar:///usr/bin/db-sync/src/Command/SyncCommand.php(178): DbSync\DbSync->sync(Object(DbSync\Table), Object(DbSync\Table), Object(DbSync\ColumnConfiguration), Object(DbSync\ColumnConfiguration))
#1 phar:///usr/bin/db-sync/src/Command/SyncCommand.php(110): DbSync\Command\SyncCommand->fire()
#2 phar:///usr/bin/db-sync/vendor/symfony/console/Command/Command.php(259): DbSync\Command\SyncCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///usr/bin/db-sync/bin/sync(75): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 phar:///usr/bin/db-sync/bin/sync(91): DbSync\Command\App->run(Object(DbSync\Command\SyncCommand))
#5 /usr/bin/db-sync(12): require('phar:///usr/bin...')
#6 {main}
The text was updated successfully, but these errors were encountered: