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

Clear destination database before each run to prevent duplicate primary key errors? #14

Closed
justinwiley opened this issue Oct 4, 2012 · 2 comments
Milestone

Comments

@justinwiley
Copy link

I generated a new whitelist via the command line utility, created a new destination database 'snapshot', and executed using the following script:

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
require 'data-anonymization'

DataAnon::Utils::Logging.logger.level = Logger::INFO

database 'Example' do
  strategy DataAnon::Strategy::Whitelist
  source_db ActiveRecord::Base.configurations['development']
  destination_db ActiveRecord::Base.configurations['snapshot']

  table 'answers' do
    primary_key 'id'
    whitelist 'question_id'
    whitelist 'name'
    whitelist 'position'
    whitelist 'value'
    whitelist 'created_at'
    whitelist 'updated_at'
  end
end

This failed, since there were no tables in the source database. I copied the table structure, and re-ran the script.

This succeeded the first time, but fails the second time, with duplicate ID errors:

Mysql2::Error: Duplicate entry '3355' for key 'PRIMARY': INSERT INTO `answers` (`created_at`, `id`, `name`, `position`, `question_id`, `updated_at`, `value`) VALUES ('2012-10-04 17:35:03', 3355, NULL, NULL, NULL, '2012-10-04 17:35:03', NULL)

Is there some way to have clear the destination database before each run?

@sunitparekh sunitparekh added this to the 0.7.0 milestone Apr 10, 2014
@sunitparekh
Copy link
Owner

Best way is to take the dump of the empty destination database and keep restoring it at the beginning of the script. example line # 1

Apologies for year late reply. I missed your message, really sorry. Might be helpful for others.

@sunitparekh
Copy link
Owner

Yes, for Whitelist Destination tables have to be created.

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

2 participants