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

Add MySql support #9

Merged
merged 28 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4440261
add mysql gem, update json_type adapter method, add recognition of my…
adlamas Sep 22, 2023
635e814
add mysql fields, add mysql db adapter
adlamas Sep 25, 2023
c5638e0
add mysql service to ci.yml
adlamas Oct 4, 2023
d439e3c
update port of mysql
adlamas Oct 4, 2023
4922841
set new ports for mysql
adlamas Oct 5, 2023
042d175
add mysql start service command
adlamas Oct 5, 2023
93d05bf
update start mysql service command
adlamas Oct 5, 2023
716ae9d
install mysql client
adlamas Oct 5, 2023
37c2c8a
update mysql image version
adlamas Oct 5, 2023
388df7d
update mysql start service command
adlamas Oct 5, 2023
78ffd40
update mysql host on docker image
adlamas Oct 5, 2023
7c289d1
update options, ports
adlamas Oct 5, 2023
4060224
update user
adlamas Oct 5, 2023
9d8f370
update password
adlamas Oct 5, 2023
4666bb6
delete user password
adlamas Oct 5, 2023
174c6ad
update spec to reflect json type in migration for mysql
adlamas Oct 27, 2023
cca3a17
update fetch of ENV variables
adlamas Oct 27, 2023
b002e83
update mysql gem version
adlamas Oct 27, 2023
86a1762
fix rubocop issues
adlamas Oct 27, 2023
1c7115f
set user and password for mysql docker container
adlamas Oct 27, 2023
ce0b318
set new ports
adlamas Oct 28, 2023
7e88e73
update port to default
adlamas Oct 28, 2023
dc1f476
remove mysql image version from ci
adlamas Oct 30, 2023
db1375d
update port
adlamas Oct 30, 2023
ff49336
add migration test for mysql adapter
adlamas Nov 1, 2023
566c47f
remove instalation of mysql client
adlamas Nov 1, 2023
591ed4a
set mysql port to default
adlamas Nov 1, 2023
7851236
bump gem version
adlamas Nov 1, 2023
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
29 changes: 28 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql
ports:
- 8888:3306
adlamas marked this conversation as resolved.
Show resolved Hide resolved
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_USER: active_outbox_user
MYSQL_PASSWORD: password
MYSQL_DATABASE: active_outbox_db
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
BUNDLE_GEMFILE: Gemfile
name: "RSpec tests: Ruby ${{ matrix.version }}"
Expand All @@ -48,4 +62,17 @@ jobs:
ADAPTER: postgresql
- name: Run RuboCop
run: bundle exec rubocop .

- name: install mysql client
adlamas marked this conversation as resolved.
Show resolved Hide resolved
run: |
sudo apt-get install -y mysql-client
- name: Start mysql service
run: sudo /etc/init.d/mysql start
- name: Run tests on mysql
run: bundle exec rspec
env:
ADAPTER: mysql2
MYSQL_DATABASE: active_outbox_db
MYSQL_HOST: 127.0.0.1
MYSQL_PORT: 8888
MYSQL_USER: active_outbox_user
MYSQL_PASSWORD: password
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gemspec
gem 'byebug', '~> 11.1.3'
gem 'database_cleaner-active_record', '~> 2.1.0'
gem 'generator_spec', '~> 0.9.4'
gem 'mysql2', '~> 0.5.2'
gem 'pg', '~> 1.5.4'
gem 'pry-rails', '~> 0.3.9'
gem 'reek', '~> 6.1.4'
Expand Down
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.3)
diff-lcs (1.5.0)
docile (1.4.0)
dry-configurable (1.1.0)
Expand Down Expand Up @@ -111,9 +110,8 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
mysql2 (0.5.5)
net-imap (0.4.2)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
Expand Down Expand Up @@ -242,6 +240,7 @@ DEPENDENCIES
byebug (~> 11.1.3)
database_cleaner-active_record (~> 2.1.0)
generator_spec (~> 0.9.4)
mysql2 (~> 0.5.2)
pg (~> 1.5.4)
pry-rails (~> 0.3.9)
reek (~> 6.1.4)
Expand Down
14 changes: 12 additions & 2 deletions lib/active_outbox/adapter_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
module ActiveOutbox
module AdapterHelper
def self.uuid_type
postgres? ? 'uuid' : 'string'
return 'uuid' if postgres?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use case? I feel it's cleaner that returns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way it would be with case

    def self.uuid_type
      case adapter
      when 'postgres'
        'uuid'
      when 'mysql2'
        'string'
      else
        'string'
      end
    end

    def self.json_type
      case adapter
      when 'postgres'
        'jsonb'
      when 'mysql2'
        'json'
      else
        'string'
      end
    end

    def self.adapter
      ActiveRecord::Base.connection.adapter_name.downcase
    end
  end

Personally, I prefer it with if statements, I don't see it more clear

return 'string' if mysql?

'string'
end

def self.json_type
postgres? ? 'jsonb' : 'string'
return 'jsonb' if postgres?
return 'json' if mysql?

'string'
end

def self.postgres?
ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
end

def self.mysql?
ActiveRecord::Base.connection.adapter_name.downcase == 'mysql2'
end
end
end
2 changes: 1 addition & 1 deletion spec/generators/active_outbox_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def change
create_table :#{table_name}_outboxes do |t|
t.string :identifier, null: false, index: { unique: true }
t.string :event, null: false
t.string :payload
adlamas marked this conversation as resolved.
Show resolved Hide resolved
t.#{ActiveOutbox::AdapterHelper.json_type} :payload
t.string :aggregate, null: false
t.string :aggregate_identifier, null: false, index: true

Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
host: ENV.fetch('POSTGRES_HOST', nil),
port: ENV.fetch('POSTGRES_PORT', nil)
}
elsif ENV['ADAPTER'] == 'mysql2'
{
adapter: 'mysql2',
username: ENV.fetch('MYSQL_USER', nil),
host: ENV.fetch('MYSQL_HOST', nil),
port: ENV.fetch('MYSQL_PORT', nil),
password: ENV.fetch('MYSQL_PASSWORD', nil),
database: ENV.fetch('MYSQL_DATABASE', nil)
}
else
{
adapter: 'sqlite3',
Expand Down