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

feat: support for MSSQL #38

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/specs_mssql_61.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Specs Rails 6.1 MSSQL

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
ruby: ['3.0', '3.1', '3.2']
gemfile: ['rails_6_1_mssql']

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
DB_TEST: mssql
MSSQL_DB_HOST: 127.0.0.1
MSSQL_DB_USERNAME: sa
MSSQL_DB_PASSWORD: Pa%%w0rd
RAILS: '6.1'

services:
postgres:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: 'Y'
SA_PASSWORD: Pa%%w0rd
ports:
- 1433:1433

steps:
- name: Install FreeTDS
run: sudo apt-get install -y freetds-dev freetds-bin

- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Database setup
run: bundle exec rails db:create db:migrate

- name: Run tests
run: bundle exec rspec --profile
53 changes: 53 additions & 0 deletions .github/workflows/specs_mssql_70.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Specs Rails 7.0 MSSQL

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
matrix:
ruby: ['3.0', '3.1', '3.2']
gemfile: ['rails_7_0_mssql']

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
DB_TEST: mssql
MSSQL_DB_HOST: 127.0.0.1
MSSQL_DB_USERNAME: sa
MSSQL_DB_PASSWORD: Pa%%w0rd
RAILS: '7.0'

services:
postgres:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: 'Y'
SA_PASSWORD: Pa%%w0rd
ports:
- 1433:1433

steps:
- name: Install FreeTDS
run: sudo apt-get install -y freetds-dev freetds-bin

- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Database setup
run: bundle exec rails db:create db:migrate

- name: Run tests
run: bundle exec rspec --profile
12 changes: 12 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ appraise 'rails-7_1-mysql' do
gem 'mysql2'
gem 'rails', '~> 7.1.0'
end

appraise 'rails-6_1-mssql' do
gem 'activerecord-sqlserver-adapter', '~> 6.1.0'
gem 'rails', '~> 6.1.0'
gem 'tiny_tds'
end

appraise 'rails-7_0-mssql' do
gem 'activerecord-sqlserver-adapter', '7.0.3.0'
gem 'rails', '~> 7.0.0'
gem 'tiny_tds'
end
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gemspec

group :development, :test do
if ENV['DB_TEST'] == 'mssql'
gem 'activerecord-sqlserver-adapter', '7.0.3.0'
gem 'tiny_tds'
end
gem 'mysql2' if ENV['DB_TEST'] == 'mysql'
gem 'pg' if ['postgres', 'postgresql'].include? ENV['DB_TEST']

gem 'simplecov'
gem 'simplecov-lcov'

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![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)
[![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)

An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database.
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database. Experimental support also for MSSQL.

Main features:
- attachment data stored in a binary field (or blob);
Expand Down
2 changes: 1 addition & 1 deletion extra/Dockerfile_32
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ruby:3.2-slim
ARG DB_TEST

RUN apt-get update
RUN apt-get install --no-install-recommends -y build-essential curl file git nano netcat-traditional libmariadb-dev libpq-dev openssl tzdata
RUN apt-get install --no-install-recommends -y build-essential curl file freetds-dev freetds-bin git nano netcat-traditional libmariadb-dev libpq-dev openssl tzdata

# App setup
WORKDIR /usr/src/app
Expand Down
48 changes: 45 additions & 3 deletions extra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@
version: "3.3"

x-defaults:
tests_mssql: &tests_mssql
environment:
CI: 1
DB_TEST: mssql
DB_PORT: 1433
MSSQL_DB_HOST: mssql
MSSQL_DB_NAME: test_db
MSSQL_DB_USERNAME: sa
MSSQL_DB_PASSWORD: Pa%%w0rd
RAILS: '7.0'
RAILS_ENV: test
command:
- sh
- -c
- |
while ! nc -z $${DB_TEST} $${DB_PORT} </dev/null
do echo "Waiting for DB ($${DB_TEST})..." && sleep 5; done
echo "DB is now available!"
cd spec/dummy70
bin/setup
cd ../..
bin/rspec
volumes:
- ..:/usr/src/app:delegated
depends_on:
- mssql

tests_mysql: &tests_mysql
environment:
CI: 1
Expand Down Expand Up @@ -57,17 +84,24 @@ x-defaults:
- postgres

services:
postgres:
image: postgres
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
platform: linux/amd64
environment:
POSTGRES_PASSWORD: password
ACCEPT_EULA: 'Y'
SA_PASSWORD: Pa%%w0rd

mysql:
image: mysql
platform: linux/amd64
environment:
MYSQL_ROOT_PASSWORD: password

postgres:
image: postgres
environment:
POSTGRES_PASSWORD: password

tests_30_mysql:
<<: *tests_mysql
build:
Expand All @@ -84,6 +118,14 @@ services:
args:
DB_TEST: postgres

tests_32_mssql:
<<: *tests_mssql
build:
context: ..
dockerfile: extra/Dockerfile_32
args:
DB_TEST: mssql

tests_32_mysql:
<<: *tests_mysql
build:
Expand Down
26 changes: 26 additions & 0 deletions gemfiles/rails_6_1_mssql.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord-sqlserver-adapter", "~> 6.1.0"
gem "rails", "~> 6.1.0"
gem "tiny_tds"

group :development, :test do
gem "simplecov"
gem "simplecov-lcov"
gem "capybara"
gem "rspec_junit_formatter"
gem "rspec-rails"
gem "selenium-webdriver"
gem "brakeman"
gem "fasterer"
gem "rubocop"
gem "rubocop-packaging"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rspec"
gem "pry-rails"
end

gemspec path: "../"
Loading
Loading