{"id":19310964,"url":"https://github.com/a0s/separatum","last_synced_at":"2025-04-22T14:30:23.586Z","repository":{"id":56894970,"uuid":"187863304","full_name":"a0s/separatum","owner":"a0s","description":"Extract and transfer linked objects from one database into another.","archived":false,"fork":false,"pushed_at":"2020-08-23T21:35:07.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T06:37:52.794Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/a0s/separatum","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a0s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-21T15:16:03.000Z","updated_at":"2020-08-23T21:35:01.000Z","dependencies_parsed_at":"2022-08-21T01:20:37.345Z","dependency_job_id":null,"html_url":"https://github.com/a0s/separatum","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a0s%2Fseparatum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a0s%2Fseparatum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a0s%2Fseparatum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a0s%2Fseparatum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a0s","download_url":"https://codeload.github.com/a0s/separatum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250258733,"owners_count":21400959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T00:27:08.920Z","updated_at":"2025-04-22T14:30:23.200Z","avatar_url":"https://github.com/a0s.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (WIP) Separatum\n\nExtract and transfer linked objects from one database into another.\n\n## How you can use it\n\n- Making seeds.rb as copy of production data for testing purposes\n- Making separate database for AB-testing (performance or marketing purposes)\n- Checking your data logical structure (it will raise on broken or unexisting links)\n- Freeze state of a set of objects in time and export them as `Object.create` ruby-code\n\n## UUID\n\nIt is better if you are using UUID primary key in every table you want to extract.\nThis will allow you to avoid problems (with primary keys and sequences) during importing objects into a new database.\nAlso `UuidChanger` can help you avoid collisions in case of importing same objects more than one time in the same database.\n\n## Examples\n\n```bash\ngem install separatum\n```\n\n```ruby\nrequire 'separatum'\n```\n\n### Extract and export\n\nBuild new exporter\n\n```ruby\nexporter = Separatum.build do\n  use Separatum::Importers::ActiveRecord  # We are going to crawl ActiveRecord objects  \n  use Separatum::Processors::UuidChanger  # Hide production's UUIDs with no broken links \n  use Separatum::Exporters::JsonFile, file_name: 'separate.json' # Export object to json file                                      \nend\n```\n\nDefine start object and extract all linked records into `separate.json` file\n\n```ruby\nstart_object = User.find('any_uuid_from_your_table')\nexporter.(start_object)\n```\n\n### Import into new database\n\nBuild new importer\n\n```ruby\nimporter = Separatum.build do\n  use Separatum::Importers::JsonFile, file_name: 'separate.json' # We are going to import hashed objects from separate.json  \n  use Separatum::Exporters::ActiveRecord # Save them (in one transaction for all objects in set)\nend\n```\n\nImport records to a database from `separate.json` file\n\n```ruby\nimporter.() # It returns set of persisted objects\n```\n\n### Extract and generate ruby code\n\n```ruby\nseeds_generator = Separatum.build do\n  use Separatum::Importers::ActiveRecord\n  use Separatum::Processors::UuidChanger  \n  use Separatum::Exporters::ActiveRecordCode\nend\n\n```\n\nReturn generated ruby code for creating objects in a database\n\n```ruby\nstart_object = User.find('any_uuid_you_want_to_start_from')\nputs seeds_generator.(start_object)\n```\n\n## Building parts\n\n### Separatum::Importers::ActiveRecord\n\nParameters:\n\n  - max_depth (default: 3)\n  - edge_classes\n  - denied_classes \n  - denied_class_transitions\n  - svg_file_name\n  - dot_file_name\n\n### Separatum::Importers::JsonFile\n\nParameters:\n\n  - file_name\n  \n### Separatum::Processors::FieldChanger\n\nParameters:\n\n  - 1st/2nd - class and field to change\n  - 3rd/4th - class and method that will make transformation \n  - 3rd  - Proc or Block \n  \n### Separatum::Exporters::ActiveRecord\n\n### Separatum::Exporters::ActiveRecordCode\n\nParameters:\n\n  - file_name\n  - ignore_not_unique_classes\n  \n  \n### Separatum::Exporters::JsonFile\n\nParameters:\n  \n  - file_name\n  - pretty_print\n\n## TODO\n\n- Better README.md :)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/a0s/separatum.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa0s%2Fseparatum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa0s%2Fseparatum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa0s%2Fseparatum/lists"}