{"id":18843727,"url":"https://github.com/fursich/dumped_railers","last_synced_at":"2025-11-11T18:23:43.254Z","repository":{"id":55854637,"uuid":"320361516","full_name":"fursich/dumped_railers","owner":"fursich","description":"import / export ActiveRecord models in Rails-compatible fixture (YAML) format","archived":false,"fork":false,"pushed_at":"2024-10-01T08:34:28.000Z","size":105,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-07T16:41:43.445Z","etag":null,"topics":["database-dump","fixture","fixture-factory","fixture-generator","rails","rails-compatible-fixture"],"latest_commit_sha":null,"homepage":"https://github.com/fursich/dumped_railers","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/fursich.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-10T18:50:02.000Z","updated_at":"2025-08-01T21:16:57.000Z","dependencies_parsed_at":"2024-12-16T04:30:53.128Z","dependency_job_id":"62f7b63b-e915-4a63-a9b8-306bb1638ad1","html_url":"https://github.com/fursich/dumped_railers","commit_stats":{"total_commits":57,"total_committers":2,"mean_commits":28.5,"dds":0.01754385964912286,"last_synced_commit":"d7c2f52ebf7bbceb5635297807fba4b062ef77cd"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/fursich/dumped_railers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fursich%2Fdumped_railers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fursich%2Fdumped_railers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fursich%2Fdumped_railers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fursich%2Fdumped_railers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fursich","download_url":"https://codeload.github.com/fursich/dumped_railers/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fursich%2Fdumped_railers/sbom","scorecard":{"id":414288,"data":{"date":"2025-08-11","repo":{"name":"github.com/fursich/dumped_railers","commit":"2c6026fe7f134c84e46e2080d1c207d84d66908e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/17 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/fursich/dumped_railers/ci.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/fursich/dumped_railers/ci.yml/main?enable=pin","Info:   0 out of   1 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 18 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T23:25:39.135Z","repository_id":55854637,"created_at":"2025-08-18T23:25:39.135Z","updated_at":"2025-08-18T23:25:39.135Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283907320,"owners_count":26914792,"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","status":"online","status_checked_at":"2025-11-11T02:00:06.610Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database-dump","fixture","fixture-factory","fixture-generator","rails","rails-compatible-fixture"],"created_at":"2024-11-08T02:58:39.453Z","updated_at":"2025-11-11T18:23:43.237Z","avatar_url":"https://github.com/fursich.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DumpedRailers    \u003cimg src='https://user-images.githubusercontent.com/23026542/101830310-aaf10000-3b77-11eb-9e0a-d14e45b27760.png' width=40\u003e\n[![Build Status](https://github.com/fursich/dumped_railers/actions/workflows/ci.yml/badge.svg)](https://github.com/fursich/dumped_railers/actions/workflows/ci.yml/badge.svg) [![Gem Version](https://badge.fury.io/rb/dumped_railers.svg)](https://badge.fury.io/rb/dumped_railers)\n\nHelping you take a snapshot of ActiveRecord models in Rails-compatible fixture format, and re-importing them wherever necessary without destroying current data you have.\n\nWith Rails, you can import any fixture data using `rails db:fixtures:load` - however, this let's you remove all the existing data in your database before importing the fixtures. This is good for clean seeding, typically when running your tests, but there are other senarios where you want to merely ADD data, without damaging the current data you are woking with.\n\nThis is a bit trickey puzzle, though. To add the imported records, you cannot dump and re-import the primary key, as they are already taken by the original records. But usually your records involve reference to associated records, where the associations are guaranteed by the very primary keys.\nIn other words, the fixures have to be stored and re-imported, so as to maintain their original inter-dependencies, but their primary keys have to be re-assigned (headache)\n\nDumpedRailers can add (not replace) the fixture without removing the current records, while restoring **all associations** among the original records.\nAdditionally, it can ignore, mask, or tweak any attributes when dumping the records into fixture files, which is convenient to export sensitive data (typically in your production environment) into, for instance, your staging environment.\n\nThis feature can particularily help you in the following senarios:\n- you want to copy a group of records without breaking the other data sets you are working on\n- you want to transfer some production data into dev environment, to reproduce some errors you encontered.\n- you work for a multi-tenancy service, where you want to duplicate interdependent set of records from tenant A to tenant B.\n- you simply want to populate interdependent record sets, which is not easy to re-build with FactoryBot\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\n# if you use this gem in production, `require: false` would be recommended\n# to prevent accidental database leakage/breakage.\n\ngem 'dumped_railers', require: false\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install dumped_railers\n\n## Usage\n\n### Getting Started\n\n* Require dumped_railers where necessary (e.g. in your rake tasks, or script files)\n\n```ruby\nrequire 'dumped_railers'\n```\n\n* if you want to dump records from (let's say) User, Item, and Tag, just run the following.\n\n```ruby\nDumpedRailers.dump!(User, Item, Tag, base_dir: 'tmp/fixtures/')\n```\nthis will generate three fixture files under tmp/fixtures/ folder.\n\n* if you want to import the records you just saved, run:\n\n```ruby\nDumpedRailers.import!('tmp/fixtures')\n```\n\n* you can also specify individual model(s) for selective import.\n\n```ruby\nDumpedRailers.import!('tmp/fixtures/users.yml', 'tmp/fixtures/items.yml')\n```\n\nNOTE: you at least have to provide all the dependent records, so that DumpedRailers can resolve dependencies among the fixtures provided.\n\n### Using In-Memory Fixtures\n\nDumpedRailers.dump! also returns an object, which can be imported directly as in-memory fixture.\n\n```ruby\nfixtures = DumpedRailers.dump!(User, Item, Tag)\nDumpedRailers.import!(fixtures)\n```\n\nDumpedRailers does not save the fixtures when `base_dir` keyword argument is not specified.\n\n### Ignoring Certain Columns\n\n* By default, DumpedRailers ignore three columns - `id`, `created_at`, `updated_at`. You can always update/change this settings as follows.\n\n```ruby\nDumpedRailers.configure do |config|\n  config.ignorable_columns += [:published_on] # :published_on will be ignored *on top of* default settings.\nend\n```\n\n* of course you can totally replace the settings with your own.\n```ruby\nDumpedRailers.configure do |config|\n  config.ignorable_columns = %i[uuid created_on updated_on] # :uuid and :created_on will be ignored *instead of* :id, :created_at, :updated_at\nend\n```\n\n### Masking, Filtering\n\n* you can pass `preprocessors` to DumpedRailers before it starts dump. All the attributes are filtered through preprocessors in order of registration.\n\n```ruby\nDumpedRailers.dump!(User, Item, base_dir: 'tmp/', preprocessors: [MaskingPreprocessor.new])\n```\n\n* \"Preprocessors\" can be lambda, or module, or any objects that can repond to #call(model, attributes).\n\n\n```ruby\nclass MaskingPreprocessor\n  def call(model, attrs)\n    attrs.each { |col, _value|\n      attrs[col] = '\u003cMASKED\u003e' if col.match?(/password/)\n    }\n  end\nend\n```\n\n* a lambda object can be accepted as well\n\n```ruby\nmasking_preprocessor = -\u003e (model, attrs) { attrs.transform_values!(\u0026:upcase) }\n```\n\nNOTE:\n* In order to reflect changes to the output, **preprocessors must change the attributes destructively**.\n* If you set multiple preprocessors, each preprocessor will be invoked sequentially from left to right, which means your second preprocessor receives attributes only after your first preprocessor update them.\n\n### Limiting Import with Authorized Models Only\n\n* In case you don't want to accept arbitrary fixtures to import, you can limit model access as follows:\n\n```ruby\nDumpedRailers.import!(fixtures, authorized_models: [Item, Price])\n```\n\nThis would allow us to import fixtures for items and prices, but reject modification on User, Purchase, Admin data.\n\nNOTE: Only DumpedRailers.import! is affected by this option. DumpedRailers.dump! can't be scoped (at least in the current version).\n\n\n### Setting Callbacks\n\n* You can set `before_save` / `after_save` callbacks for import! method.\nThe callbacks are invoked just before/after each table's records are saved.\n\n```ruby\nbefore_callback = -\u003e (model, records) {\n  if model == User\n    # set random initial passwords before saving\n    records.each do |user|\n      user.password = user.password_confirmation = SecureRandom.hex(12)\n    end\n  end\n}\n\nafter_callback1 = -\u003e (model, records) {\n  if model == User\n    records.each do |user|\n      user.confirm!\n    end\n  end\n}\n\nafter_callback2 = -\u003e (model, records) {\n  if model == Admin\n    records.each |admin|\n      notify_to_slack(admin.email, admin.name)\n    end\n  end\n}\n\nDumpedRailers.import!(fixture_path, before_save: before_callback, after_save: [after_callback1, after_callback2])\n```\n\n`before_save` /  `after_save` can accept both single and multiple (array) arguments.\n\n### Deserializing Custom Classes with YAML\n\n* YAML (Psych) does not permit to load random class objects for [security reasons](https://discuss.rubyonrails.org/t/cve-2022-32224-possible-rce-escalation-bug-with-serialized-columns-in-active-record/81017).\n* By default, DumpedRailers handles all the objects that Rails permitts (i.e. [ActiveRecord.yaml_column_permitted_classes](https://guides.rubyonrails.org/configuring.html#config-active-record-yaml-column-permitted-classes)), plus Time, Date, and DateTime.\n* DumpedRailers raises `Psych::DisallowedClass` error when non-permitted classes are detected. If you want DumpedRailsers handle other classes, you could specify `yaml_column_permitted_classes` option with configurations or import method's arguments.\n* *Please use this option with extra care* for security - again, it is recommended to use this for development purpose only.\n\n```ruby\nDumpedRailers.configure do |config|\n  config.ignorable_columns += [:published_on] # :published_on will be ignored *on top of* default settings.\nend\n```\n\n#### Caveats\n* If you wish to load Date, Time object, it would be easier to load it as a string. DumpedRailers will pass it to the specified ActiveRecord models and they typecast the raw string into the appropreate date/time object.\n\n* below columns (published_date, published_time, first_drafted_at) all will be passed as a string (as the value is surrounded by the quotes). Strings will be interperted to apropreate column type with ActiveRecord.\n\n```ruby\n_fixture:\n  model_class: Article\n  fixture_generated_by: DumpedRailers\n__article_1:\n  title: Harry Potter\n  published_date: '2024-03-01'\n  published_time: '10:00:00'\n  first_drafted_at: '2024-02-01T10:10:10+09:00'\n```\n\n* below fixture (without quotes) will be directly interperted to Date or Time via YAML module. It needs to have proper format that YAML can interpret.\n\n```ruby\n_fixture:\n  model_class: Article\n  fixture_generated_by: DumpedRailers\n__article_1:\n  title: Harry Potter\n  published_date: 2024-03-01\n  published_time: 2000-01-01 10:00:00\n  first_drafted_at: 2024-02-01T10:10:10+09:00\n```\n\n### Configuration\n\n* All the settings can be configured by either configuration (global) or arguments (at runtime).\n* When you have duplicated setting, arguments are respected: you can always override configured settings by arguments.\n\n```ruby\nDumpedRailers.configure do |config|\n  config.ignorable_columns = [:archived_at]\n  config.preprocessors = [FooPreprocessor, BarPreprocessor]\nend\n\nDumpedRailers.dump!(Item, ignorable_columns: [:id], preprocessors: [BazPreprocessor], base_dir: 'tmp/')\n# this would ignore `id` column, and apply BazPreprocessor only\n\nDumpedRailers.dump!(Price, base_dir: 'tmp/')\n# this would ignore `archived_at`, applies FooPreprocessor and BazPreprocessor\n# (settings provided with arguments are considered as one-off, and don't survive globally)\n```\n\n### Dump/Import under default_scope (e.g. ActsAsTenant)\n\n* Such library builds multi-tenancy environment on one single database, using default_scope to switch over database access rights between tenants. You can incorporate data from Tenant A to Tenant B as follows. let's say we use [ActsAsTenant](https://github.com/ErwinM/acts_as_tenant)\n\n```ruby\n# make sure to delete old fixtures in the folder\nFile.delete(Dir.glob('tmp/fixtures/{**,*}/*.yml'))\n\n# let DumpedRailers ignore tenant column, as it will be overwritten by ActsAsTenant\nDumpedRailers.configure do |config|\n  config.ignorable_columns += [:account_id]\nend\n\n# dump from tenant_a\nActsAsTenant.with_tenant(tenant_a) do\n  DumpedRailers.dump!(Item, Tag, base_dir: 'tmp/fixtures/')\nend\n\n# import into tenant_b\nActsAsTenant.with_tenant(tenant_b) do\n  DumpedRailers.import!('tmp/fixtures')\nend\n```\n\n## Troubleshooting\n\nWhen DumpedRailers fail to resolve dependencies, please check the following.\n\n* DumpedRailers uses ActiveRecord reflection methods to sort out model dependencies. You might have to check wheather your relation is defined on the model (especially, `belongs_to` cannot be omitted).\n\n* Dependencies cannot be resolved when cyclic dependencies are detected. For instance, the case like below cannot be resolved.\n\n```ruby\nclass Chicken \u003c ActiveRecord::Base\n  belongs_to :egg, optional: true\nend\n\nclass Egg \u003c ActiveRecord::Base\n  belongs_to :chicken, optional: true\nend\n```\n\n* For the same reason, self-associated model cannot be imported currently. (might be updated in the future version)\n\n* When an exception was raised, checking your log might give you a good hint (desperately staring at the backtrace won't give much information)\n  consider displaying `tail -f logs/development.log` while executing your script.\n\n* DumpedRailers is tested against various association types, as long as target models and underlying tables have 1-on-1 mapping (straightforward ActiveRecord pattern). Currently we haven't test this against STI, CTI, as such. Applying this gem to such models might lead to some unexpected results.\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/fursich/dumped_railers.\n\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%2Ffursich%2Fdumped_railers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffursich%2Fdumped_railers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffursich%2Fdumped_railers/lists"}