Skip to content

Commit 279d634

Browse files
authored
Merge pull request #51 from blocknotes/feat/sqlite-support
feat: SQLite support
2 parents 9e0157f + 71448c5 commit 279d634

13 files changed

Lines changed: 1145 additions & 13 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: Specs Rails 7.2 SQLite
3+
4+
on:
5+
pull_request:
6+
branches: [main]
7+
push:
8+
branches: [main]
9+
10+
jobs:
11+
tests:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
ruby: ['3.3']
17+
gemfile: ['rails_7_2_sqlite']
18+
19+
env:
20+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
21+
DB_TEST: sqlite
22+
RAILS: '7.0'
23+
24+
steps:
25+
- name: Install lib VIPS
26+
run: sudo apt-get install -y libvips-dev
27+
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Ruby
32+
uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: ${{ matrix.ruby }}
35+
bundler-cache: true
36+
37+
- name: Database setup
38+
run: bundle exec rails db:create db:migrate
39+
40+
- name: Run tests
41+
run: bundle exec rspec --profile
42+
43+
- name: Code Climate test coverage
44+
uses: paambaati/codeclimate-action@v3.0.0
45+
env:
46+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
47+
with:
48+
coverageLocations: |
49+
${{github.workspace}}/coverage/lcov/active_storage_db.lcov:lcov
50+
51+
# - name: Upload coverage results
52+
# uses: actions/upload-artifact@main
53+
# if: always()
54+
# with:
55+
# name: coverage-report
56+
# path: coverage/index.html

Appraisals

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,18 @@ appraise 'rails-7_0-mssql' do
4141
gem 'rails', '~> 7.0.0'
4242
gem 'tiny_tds'
4343
end
44+
45+
appraise 'rails-6_1-sqlite' do
46+
gem 'sqlite3', '~> 1.4'
47+
gem 'rails', '~> 6.1.0'
48+
end
49+
50+
appraise 'rails-7_1-sqlite' do
51+
gem 'sqlite3', '~> 1.4'
52+
gem 'rails', '~> 7.1.0'
53+
end
54+
55+
appraise 'rails-7_2-sqlite' do
56+
gem 'sqlite3', '~> 1.4'
57+
gem 'rails', '~> 7.2.0'
58+
end

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![specs Postgres](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_71.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_71.yml)
99
[![specs MySQL](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_71.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_71.yml)
1010

11-
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database. Experimental support also for MSSQL.
11+
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database. Experimental support also for MSSQL and SQLite.
1212

1313
Main features:
1414
- attachment data stored in a binary field (or blob);
@@ -31,29 +31,29 @@ db:
3131
service: DB
3232
```
3333
34-
If there is a need to support a separate database connection for storing the `ActiveStorageDB` files:
34+
### Customizations
3535
36-
1. Add a separate database configuration for the environment (this one is just an example)
36+
To setup a separate database connection for the `ActiveStorageDB` migrations and files data:
37+
38+
1. Add a different database configuration per environment to `config/database.yml`, e.g:
3739

3840
```yml
3941
attachments:
4042
database: attachments
41-
pool: 5
42-
username: root
4343
migrations_paths: config/attachments_migrate
44+
# other connection details ...
4445
```
4546

46-
2. Create a separate initializer file in `config/initializera/active_storage_db.rb` to set the database:
47+
2. Extend the ActiveStorage base record class providing the `connects_to` options, e.g `app/overrides/models/active_storage_db/application_record_override.rb` (or add an initializer for _ActiveStorageDB_):
4748

4849
```rb
49-
# app/overrides/models/active_storage_db/application_record_override.rb
5050
ActiveStorageDB::ApplicationRecord.class_eval do
5151
connects_to database: { reading: :attachments, writing: :attachments }
5252
end
5353
```
5454

55-
3. Move the `ActiveStorageDB` related migrations to a configured storage migrations path
56-
4. Create the database and execute the migrations
55+
3. Move the _ActiveStorageDB_ migrations to the specified migrations path
56+
4. Execute the _rails db:migrate_ task
5757

5858
## Misc
5959

@@ -74,9 +74,9 @@ If you use this component just star it. A developer is more motivated to improve
7474

7575
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
7676

77-
## Contributors
77+
## Development
7878

79-
- [Mattia Roccoberton](https://blocknot.es/): author
79+
- Author: [Mattia Roccoberton](https://blocknot.es/)
8080
- Inspired by [activestorage-database-service](https://github.com/TitovDigital/activestorage-database-service) project
8181

8282
## License

gemfiles/rails_6_1_sqlite.gemfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "image_processing", ">= 1.2"
6+
gem "webrick"
7+
gem "simplecov"
8+
gem "simplecov-lcov"
9+
gem "capybara"
10+
gem "rspec_junit_formatter"
11+
gem "rspec-rails"
12+
gem "selenium-webdriver"
13+
gem "brakeman"
14+
gem "fasterer"
15+
gem "rubocop"
16+
gem "rubocop-packaging"
17+
gem "rubocop-performance"
18+
gem "rubocop-rails"
19+
gem "rubocop-rspec"
20+
gem "pry-rails"
21+
gem "sqlite3", "~> 1.4"
22+
gem "rails", "~> 6.1.0"
23+
24+
gemspec path: "../"

0 commit comments

Comments
 (0)