{"id":15464868,"url":"https://github.com/blocknotes/active_storage_db","last_synced_at":"2025-04-07T05:08:33.777Z","repository":{"id":42707855,"uuid":"286044297","full_name":"blocknotes/active_storage_db","owner":"blocknotes","description":"An ActiveStorage service plugin to store files in a PostgreSQL / MySQL / MSSQL database","archived":false,"fork":false,"pushed_at":"2025-04-05T22:39:08.000Z","size":270,"stargazers_count":40,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-05T23:24:08.527Z","etag":null,"topics":["activestorage","activestorage-service","mysql","postgres","postgresql","rails","ruby"],"latest_commit_sha":null,"homepage":"","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/blocknotes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"MIT-LICENSE","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},"funding":{"github":["blocknotes"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-08-08T13:02:53.000Z","updated_at":"2025-04-03T11:40:17.000Z","dependencies_parsed_at":"2022-08-31T14:31:36.941Z","dependency_job_id":"f495b841-a050-4ad4-9cc1-d66f8cbeda9e","html_url":"https://github.com/blocknotes/active_storage_db","commit_stats":{"total_commits":95,"total_committers":5,"mean_commits":19.0,"dds":0.631578947368421,"last_synced_commit":"885f6e7f49e3be68e3a95c5c59f66055c93cbea5"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Factive_storage_db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Factive_storage_db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Factive_storage_db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Factive_storage_db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blocknotes","download_url":"https://codeload.github.com/blocknotes/active_storage_db/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415465,"owners_count":20935379,"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":["activestorage","activestorage-service","mysql","postgres","postgresql","rails","ruby"],"created_at":"2024-10-02T00:43:17.268Z","updated_at":"2025-04-07T05:08:33.764Z","avatar_url":"https://github.com/blocknotes.png","language":"Ruby","readme":"# Active Storage DB\n\n[![gem version](https://badge.fury.io/rb/active_storage_db.svg)](https://badge.fury.io/rb/active_storage_db)\n[![gem downloads](https://badgen.net/rubygems/dt/active_storage_db)](https://rubygems.org/gems/active_storage_db)\n[![maintainability](https://api.codeclimate.com/v1/badges/92e1e703c308744a0f66/maintainability)](https://codeclimate.com/github/blocknotes/active_storage_db/maintainability)\n\n[![linters](https://github.com/blocknotes/active_storage_db/actions/workflows/linters.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/linters.yml)\n[![Specs Postgres Ruby 3.4](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_ruby34.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_ruby34.yml)\n[![Specs MySQL Ruby 3.4](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_ruby34.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_ruby34.yml)\n\nAn Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database.\nExperimental support also for MSSQL and SQLite.\n\nAttachment data get stored in a binary field (or blob).\n\nUseful also with platforms like Heroku (due to their ephemeral file system).\n\n## Installation\n\n- Setup Active Storage in your Rails application\n- Add to your Gemfile `gem 'active_storage_db'` (and execute: `bundle`)\n- Install the gem migrations: `bin/rails active_storage_db:install:migrations` (and execute: `bin/rails db:migrate`)\n- Add to your `config/routes.rb`: `mount ActiveStorageDB::Engine =\u003e '/active_storage_db'`\n- Change Active Storage service in *config/environments/development.rb* to: `config.active_storage.service = :db`\n- Add to *config/storage.yml*:\n\n```yml\ndb:\n  service: DB\n```\n\n### Customizations\n\nTo setup a separate database connection for the `ActiveStorageDB` migrations and files data:\n\n1. Add a different database configuration per environment to `config/database.yml`, e.g:\n\n```yml\nattachments:\n  database: attachments\n  migrations_paths: config/attachments_migrate\n  # other connection details ...\n```\n\n2. Extend the ActiveStorage base record class providing the `connects_to` options (updating _config/application.rb_ / using an initializer for _ActiveStorageDB_ / overriding the base model like in the [Rails guide](https://guides.rubyonrails.org/engines.html#overriding-models-and-controllers)):\n\n```rb\n# e.g. app/overrides/models/active_storage_db/application_record_override.rb\nActiveStorageDB::ApplicationRecord.class_eval do\n  connects_to database: { reading: :attachments, writing: :attachments }\nend\n```\n\n3. Move the _ActiveStorageDB_ migrations to the specified migrations path\n4. Execute the _rails db:migrate_ task\n\n## Misc\n\nSome utility tasks are available:\n\n```sh\n# list attachments ordered by blob id desc (with limit 100):\nbin/rails 'asdb:list'\n# search attachments by filename (or part of it)\nbin/rails 'asdb:search[some_filename]'\n# download attachment by blob id (retrieved with list or search tasks) - the second argument is the destination:\nbin/rails 'asdb:download[123,/tmp]'\n```\n\n## Development\n\nProject created by [Mattia Roccoberton](http://blocknot.es), thanks also to the good guys that opened issues and pull requests from time to time.\n\nFor development information please check [this document](extra/development.md).\n\n## Do you like it? Star it!\n\nIf you use this component just star it. A developer is more motivated to improve a project when there is some interest.\n\nOr consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":["https://github.com/sponsors/blocknotes"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknotes%2Factive_storage_db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblocknotes%2Factive_storage_db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknotes%2Factive_storage_db/lists"}