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

Do not sync table that does not have a primary key #7

Closed
tmtben opened this issue Dec 1, 2015 · 6 comments
Closed

Do not sync table that does not have a primary key #7

tmtben opened this issue Dec 1, 2015 · 6 comments

Comments

@tmtben
Copy link

tmtben commented Dec 1, 2015

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}

@tmtben tmtben changed the title Don not sync table that does not have a primary key Do not sync table that does not have a primary key Dec 1, 2015
@aommiez
Copy link

aommiez commented Dec 1, 2015

me too , T-T wait fix bugs

@mrjgreen
Copy link
Owner

mrjgreen commented Dec 1, 2015

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
Joe Green

On 1 Dec 2015, at 11:10, tmtben notifications@github.com wrote:

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}


Reply to this email directly or view it on GitHub.

@tmtben
Copy link
Author

tmtben commented Dec 1, 2015

Yes, every table should have a primary key.
I've added primary key when needed, everything's ok :)
Maybe just add this point in the readme file ?

@LeftPinkie
Copy link

Every table should probably have a key... What's the use case?

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.

@mrjgreen
Copy link
Owner

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
Joe Green

On 30 Mar 2016, at 14:47, Phuong notifications@github.com wrote:

Every table should probably have a key... What's the use case?

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.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@LeftPinkie
Copy link

@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.

This issue was closed.
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

No branches or pull requests

4 participants