From cb7d063e77d2203794215155976ac62d9505d72f Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 20 Dec 2022 16:03:07 -0300 Subject: [PATCH 01/32] Introduce edgestitch --- packages/edgestitch/.gitignore | 10 + packages/edgestitch/.rubocop.yml | 2 + packages/edgestitch/Gemfile | 9 + packages/edgestitch/Gemfile.lock | 257 ++++++++++++++++++ packages/edgestitch/Rakefile | 12 + packages/edgestitch/edgestitch.gemspec | 47 ++++ packages/edgestitch/lib/edgestitch.rb | 14 + .../edgestitch/lib/edgestitch/exporter.rb | 59 ++++ .../edgestitch/lib/edgestitch/mysql/dump.rb | 70 +++++ .../structure_constraint_order_munger.rb | 58 ++++ packages/edgestitch/lib/edgestitch/railtie.rb | 9 + .../edgestitch/lib/edgestitch/renderer.rb | 26 ++ .../edgestitch/lib/edgestitch/stitch.sql.erb | 10 + packages/edgestitch/lib/edgestitch/tasks.rb | 55 ++++ packages/edgestitch/lib/edgestitch/version.rb | 5 + packages/edgestitch/spec/dummy/.ruby-version | 1 + packages/edgestitch/spec/dummy/Rakefile | 12 + .../dummy/app/models/application_record.rb | 5 + .../spec/dummy/app/models/concerns/.keep | 0 packages/edgestitch/spec/dummy/bin/rails | 6 + packages/edgestitch/spec/dummy/bin/rake | 6 + packages/edgestitch/spec/dummy/bin/setup | 35 +++ packages/edgestitch/spec/dummy/config.ru | 7 + .../spec/dummy/config/application.rb | 22 ++ packages/edgestitch/spec/dummy/config/boot.rb | 7 + .../edgestitch/spec/dummy/config/cable.yml | 10 + .../edgestitch/spec/dummy/config/database.yml | 29 ++ .../spec/dummy/config/environment.rb | 7 + .../dummy/config/environments/development.rb | 64 +++++ .../dummy/config/environments/production.rb | 114 ++++++++ .../spec/dummy/config/environments/test.rb | 51 ++++ .../application_controller_renderer.rb | 9 + .../spec/dummy/config/initializers/assets.rb | 13 + .../initializers/backtrace_silencers.rb | 8 + .../initializers/content_security_policy.rb | 29 ++ .../config/initializers/cookies_serializer.rb | 7 + .../initializers/filter_parameter_logging.rb | 6 + .../dummy/config/initializers/inflections.rb | 17 ++ .../dummy/config/initializers/mime_types.rb | 5 + .../config/initializers/wrap_parameters.rb | 16 ++ .../spec/dummy/config/locales/en.yml | 33 +++ packages/edgestitch/spec/dummy/config/puma.rb | 40 +++ .../edgestitch/spec/dummy/config/routes.rb | 5 + .../edgestitch/spec/dummy/config/spring.rb | 8 + .../edgestitch/spec/dummy/config/storage.yml | 34 +++ .../spec/dummy/db/structure-self.sql | 3 + .../edgestitch/spec/dummy/db/structure.sql | 126 +++++++++ .../models/marketing/application_record.rb | 7 + .../marketing/app/models/marketing/lead.rb | 6 + .../20221219203032_create_marketing_leads.rb | 11 + .../engines/marketing/db/structure-self.sql | 10 + .../engines/marketing/lib/marketing/engine.rb | 11 + .../app/models/payroll/application_record.rb | 7 + .../payroll/app/models/payroll/salary.rb | 6 + .../dummy/engines/payroll/db/extra_tables | 2 + .../20221219195431_create_payroll_salaries.rb | 11 + ...on_migration.acts_as_taggable_on_engine.rb | 34 +++ ...ache_to_tags.acts_as_taggable_on_engine.rb | 17 ++ ...or_tag_names.acts_as_taggable_on_engine.rb | 13 + ..._on_taggings.acts_as_taggable_on_engine.rb | 25 ++ ..._to_taggings.acts_as_taggable_on_engine.rb | 14 + .../engines/payroll/db/structure-self.sql | 50 ++++ .../engines/payroll/lib/payroll/engine.rb | 11 + .../app/models/sales/application_record.rb | 7 + .../engines/sales/app/models/sales/price.rb | 6 + .../20221219191938_create_sales_prices.rb | 11 + .../dummy/engines/sales/db/structure-self.sql | 10 + .../dummy/engines/sales/lib/sales/engine.rb | 11 + .../edgestitch/spec/dummy/lib/assets/.keep | 0 packages/edgestitch/spec/dummy/log/.keep | 0 .../spec/fixtures/files/expected-sales.sql | 10 + .../fixtures/files/expected-structure.sql | 86 ++++++ .../spec/patchwork/exporter_spec.rb | 35 +++ .../spec/patchwork/renderer_spec.rb | 36 +++ .../edgestitch/spec/patchwork/tasks_spec.rb | 110 ++++++++ packages/edgestitch/spec/rails_helper.rb | 24 ++ packages/edgestitch/spec/spec_helper.rb | 98 +++++++ 77 files changed, 2057 insertions(+) create mode 100644 packages/edgestitch/.gitignore create mode 100644 packages/edgestitch/.rubocop.yml create mode 100644 packages/edgestitch/Gemfile create mode 100644 packages/edgestitch/Gemfile.lock create mode 100644 packages/edgestitch/Rakefile create mode 100644 packages/edgestitch/edgestitch.gemspec create mode 100644 packages/edgestitch/lib/edgestitch.rb create mode 100644 packages/edgestitch/lib/edgestitch/exporter.rb create mode 100644 packages/edgestitch/lib/edgestitch/mysql/dump.rb create mode 100644 packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb create mode 100644 packages/edgestitch/lib/edgestitch/railtie.rb create mode 100644 packages/edgestitch/lib/edgestitch/renderer.rb create mode 100644 packages/edgestitch/lib/edgestitch/stitch.sql.erb create mode 100644 packages/edgestitch/lib/edgestitch/tasks.rb create mode 100644 packages/edgestitch/lib/edgestitch/version.rb create mode 100644 packages/edgestitch/spec/dummy/.ruby-version create mode 100644 packages/edgestitch/spec/dummy/Rakefile create mode 100644 packages/edgestitch/spec/dummy/app/models/application_record.rb create mode 100644 packages/edgestitch/spec/dummy/app/models/concerns/.keep create mode 100755 packages/edgestitch/spec/dummy/bin/rails create mode 100755 packages/edgestitch/spec/dummy/bin/rake create mode 100755 packages/edgestitch/spec/dummy/bin/setup create mode 100644 packages/edgestitch/spec/dummy/config.ru create mode 100644 packages/edgestitch/spec/dummy/config/application.rb create mode 100644 packages/edgestitch/spec/dummy/config/boot.rb create mode 100644 packages/edgestitch/spec/dummy/config/cable.yml create mode 100644 packages/edgestitch/spec/dummy/config/database.yml create mode 100644 packages/edgestitch/spec/dummy/config/environment.rb create mode 100644 packages/edgestitch/spec/dummy/config/environments/development.rb create mode 100644 packages/edgestitch/spec/dummy/config/environments/production.rb create mode 100644 packages/edgestitch/spec/dummy/config/environments/test.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/assets.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/cookies_serializer.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/filter_parameter_logging.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/inflections.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/mime_types.rb create mode 100644 packages/edgestitch/spec/dummy/config/initializers/wrap_parameters.rb create mode 100644 packages/edgestitch/spec/dummy/config/locales/en.yml create mode 100644 packages/edgestitch/spec/dummy/config/puma.rb create mode 100644 packages/edgestitch/spec/dummy/config/routes.rb create mode 100644 packages/edgestitch/spec/dummy/config/spring.rb create mode 100644 packages/edgestitch/spec/dummy/config/storage.yml create mode 100644 packages/edgestitch/spec/dummy/db/structure-self.sql create mode 100644 packages/edgestitch/spec/dummy/db/structure.sql create mode 100644 packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/application_record.rb create mode 100644 packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/lead.rb create mode 100644 packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb create mode 100644 packages/edgestitch/spec/dummy/engines/marketing/db/structure-self.sql create mode 100644 packages/edgestitch/spec/dummy/engines/marketing/lib/marketing/engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/application_record.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/salary.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/lib/payroll/engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/sales/app/models/sales/application_record.rb create mode 100644 packages/edgestitch/spec/dummy/engines/sales/app/models/sales/price.rb create mode 100644 packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb create mode 100644 packages/edgestitch/spec/dummy/engines/sales/db/structure-self.sql create mode 100644 packages/edgestitch/spec/dummy/engines/sales/lib/sales/engine.rb create mode 100644 packages/edgestitch/spec/dummy/lib/assets/.keep create mode 100644 packages/edgestitch/spec/dummy/log/.keep create mode 100644 packages/edgestitch/spec/fixtures/files/expected-sales.sql create mode 100644 packages/edgestitch/spec/fixtures/files/expected-structure.sql create mode 100644 packages/edgestitch/spec/patchwork/exporter_spec.rb create mode 100644 packages/edgestitch/spec/patchwork/renderer_spec.rb create mode 100644 packages/edgestitch/spec/patchwork/tasks_spec.rb create mode 100644 packages/edgestitch/spec/rails_helper.rb create mode 100644 packages/edgestitch/spec/spec_helper.rb diff --git a/packages/edgestitch/.gitignore b/packages/edgestitch/.gitignore new file mode 100644 index 00000000..58a53199 --- /dev/null +++ b/packages/edgestitch/.gitignore @@ -0,0 +1,10 @@ +.bundle/ +log/*.log +pkg/ +spec/dummy/db/*.sqlite3 +spec/dummy/db/*.sqlite3-journal +spec/dummy/db/*.sqlite3-* +spec/dummy/log/*.log +spec/dummy/storage/ +spec/dummy/tmp/ +coverage diff --git a/packages/edgestitch/.rubocop.yml b/packages/edgestitch/.rubocop.yml new file mode 100644 index 00000000..c55270c7 --- /dev/null +++ b/packages/edgestitch/.rubocop.yml @@ -0,0 +1,2 @@ +require: + - rubocop-powerhome diff --git a/packages/edgestitch/Gemfile b/packages/edgestitch/Gemfile new file mode 100644 index 00000000..b85a9cbb --- /dev/null +++ b/packages/edgestitch/Gemfile @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec + +rails_version = ENV.fetch("RAILS_VERSION", ">= 5.2.8.1") + +gem "rails", rails_version diff --git a/packages/edgestitch/Gemfile.lock b/packages/edgestitch/Gemfile.lock new file mode 100644 index 00000000..bfee26af --- /dev/null +++ b/packages/edgestitch/Gemfile.lock @@ -0,0 +1,257 @@ +PATH + remote: . + specs: + edgestitch (0.1.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.4) + actionpack (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activesupport (= 7.0.4) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.4) + actionview (= 7.0.4) + activesupport (= 7.0.4) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.4) + actionpack (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.4) + activesupport (= 7.0.4) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.4) + activesupport (= 7.0.4) + globalid (>= 0.3.6) + activemodel (7.0.4) + activesupport (= 7.0.4) + activerecord (7.0.4) + activemodel (= 7.0.4) + activesupport (= 7.0.4) + activestorage (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activesupport (= 7.0.4) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + acts-as-taggable-on (9.0.1) + activerecord (>= 6.0, < 7.1) + ast (2.4.2) + builder (3.2.4) + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.1.10) + crass (1.0.6) + date (3.3.3) + diff-lcs (1.5.0) + docile (1.1.5) + erubi (1.11.0) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + json (2.6.3) + license_finder (7.1.0) + bundler + rubyzip (>= 1, < 3) + thor (~> 1.2) + tomlrb (>= 1.3, < 2.1) + with_env (= 1.1.0) + xml-simple (~> 1.1.9) + loofah (2.19.1) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.8.0) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + minitest (5.16.3) + mysql2 (0.5.3) + net-imap (0.3.2) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.5.8) + nokogiri (1.13.10-arm64-darwin) + racc (~> 1.4) + parallel (1.22.1) + parser (3.1.3.0) + ast (~> 2.4.1) + pry (0.13.1) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.9.0) + byebug (~> 11.0) + pry (~> 0.13.0) + racc (1.6.1) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (7.0.4) + actioncable (= 7.0.4) + actionmailbox (= 7.0.4) + actionmailer (= 7.0.4) + actionpack (= 7.0.4) + actiontext (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activemodel (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) + bundler (>= 1.15.0) + railties (= 7.0.4) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.4.4) + loofah (~> 2.19, >= 2.19.1) + railties (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rainbow (3.1.1) + rake (13.0.6) + regexp_parser (2.6.1) + rexml (3.2.5) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-rails (5.1.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + railties (>= 5.2) + rspec-core (~> 3.10) + rspec-expectations (~> 3.10) + rspec-mocks (~> 3.10) + rspec-support (~> 3.10) + rspec-support (3.12.0) + rubocop (1.40.0) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.1.2.1) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.24.0) + parser (>= 3.1.1.0) + rubocop-performance (1.15.1) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-powerhome (0.5.0) + rubocop + rubocop-performance + rubocop-rails + rubocop-rake + rubocop-rspec + rubocop-rails (2.17.3) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.16.0) + rubocop (~> 1.33) + ruby-progressbar (1.11.0) + rubyzip (2.3.2) + simplecov (0.15.1) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + thor (1.2.1) + timeout (0.3.1) + tomlrb (2.0.3) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + unicode-display_width (2.3.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + with_env (1.1.0) + xml-simple (1.1.9) + rexml + yard (0.9.21) + zeitwerk (2.6.6) + +PLATFORMS + arm64-darwin-22 + +DEPENDENCIES + acts-as-taggable-on (~> 9.0) + bundler (~> 2.1) + license_finder (>= 7.0) + mysql2 (= 0.5.3) + edgestitch! + pry-byebug (= 3.9.0) + rails (>= 5.2.8.1) + rake (~> 13.0) + rspec (~> 3.0) + rspec-rails (~> 5.1.2) + rubocop-powerhome (= 0.5.0) + simplecov (= 0.15.1) + yard (= 0.9.21) + +BUNDLED WITH + 2.3.26 diff --git a/packages/edgestitch/Rakefile b/packages/edgestitch/Rakefile new file mode 100644 index 00000000..704ccf0d --- /dev/null +++ b/packages/edgestitch/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "rspec/core/rake_task" +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" +RuboCop::RakeTask.new(:rubocop) + +APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__) +load "rails/tasks/engine.rake" + +task default: %i[rubocop app:db:prepare spec] diff --git a/packages/edgestitch/edgestitch.gemspec b/packages/edgestitch/edgestitch.gemspec new file mode 100644 index 00000000..76a88153 --- /dev/null +++ b/packages/edgestitch/edgestitch.gemspec @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +$LOAD_PATH.push File.expand_path("lib", __dir__) + +require "edgestitch/version" + +Gem::Specification.new do |spec| + spec.name = "edgestitch" + spec.version = Edgestitch::VERSION + spec.authors = ["Carlos Palhares"] + spec.email = ["chjunior@gmail.com"] + + spec.summary = "Power-ful logging wrapper" + spec.description = "Lumberaxe handles logging output formatting." + spec.homepage = "https://github.com/powerhome/power-tools" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.7" + + spec.metadata["rubygems_mfa_required"] = "true" + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/lumberaxe/docs/CHANGELOG.md" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(__dir__) do + `git ls-files -z`.split("\x0").reject do |f| + (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) + end + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.add_development_dependency "acts-as-taggable-on", "~> 9.0" + spec.add_development_dependency "bundler", "~> 2.1" + spec.add_development_dependency "license_finder", ">= 7.0" + spec.add_development_dependency "mysql2", "0.5.3" + spec.add_development_dependency "pry-byebug", "3.9.0" + spec.add_development_dependency "rails", ">= 5.2.8.1" + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "rspec-rails", "~> 5.1.2" + spec.add_development_dependency "rubocop-powerhome", "0.5.0" + spec.add_development_dependency "simplecov", "0.15.1" + spec.add_development_dependency "yard", "0.9.21" +end diff --git a/packages/edgestitch/lib/edgestitch.rb b/packages/edgestitch/lib/edgestitch.rb new file mode 100644 index 00000000..3d45269e --- /dev/null +++ b/packages/edgestitch/lib/edgestitch.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require "edgestitch/exporter" +require "edgestitch/renderer" +require "edgestitch/tasks" +require "edgestitch/version" + +require "edgestitch/mysql/dump" + +# TODO: doc +# @private +module Edgestitch + def self.install_self; end +end diff --git a/packages/edgestitch/lib/edgestitch/exporter.rb b/packages/edgestitch/lib/edgestitch/exporter.rb new file mode 100644 index 00000000..bc8d80cf --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/exporter.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Edgestitch + # TODO: doc + # @private + class Exporter + def self.export(engine, dump) + new(engine).export(dump) + end + + attr_reader :engine + + def initialize(engine) + @engine = engine + @database_directory_path = engine.root.join("db") + @extra_tables_path = @database_directory_path.join("extra_tables") + @structure_file_path = @database_directory_path.join("structure-self.sql") + end + + def export(dump, io: @structure_file_path.open("w")) + io.puts [dump.export_tables(tables), dump.export_migrations(migrations)].join("\n\n").strip + end + + def migrations + @migrations ||= begin + migrations_glob = @database_directory_path.join("{migrate,migrate.archive}/*.rb") + Dir[migrations_glob] + .map { |filename| File.basename(filename).to_i } + .sort + end + end + + def tables + component_tables + extra_tables + end + + private + + def extra_tables + @extra_tables ||= @extra_tables_path.exist? ? @extra_tables_path.readlines.map(&:strip) : [] + end + + def component_tables + @component_tables ||= models.each_with_object(Set.new) do |model, tables| + tables << model.table_name if model.table_exists? + end.sort + end + + def models + @models ||= application_record&.descendants || [] + end + + def application_record + @application_record ||= engine.railtie_namespace&.const_get(:ApplicationRecord, false) + rescue LoadError, NameError + nil + end + end +end diff --git a/packages/edgestitch/lib/edgestitch/mysql/dump.rb b/packages/edgestitch/lib/edgestitch/mysql/dump.rb new file mode 100644 index 00000000..cd559604 --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/mysql/dump.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require "open3" + +require_relative "./structure_constraint_order_munger" + +module Edgestitch + module Mysql + # TODO: doc + # @private + class Dump + def self.sanitize_sql(sql) + comment_instructions_regex = %r{^/\*![0-9]{5}\s+[^;]+;\s*$} + + cleanups = sql.gsub(/\s+AUTO_INCREMENT=\d+/, "") + .gsub(/CONSTRAINT `_+fk_/, "CONSTRAINT `fk_") + .gsub(comment_instructions_regex, "") + .gsub(/\n\s*\n\s*\n/, "\n\n") + .strip + ::Edgestitch::Mysql::StructureConstraintOrderMunger.munge(cleanups) + end + + def initialize(config) + hash = config.respond_to?(:config) ? config.config : config.configuration_hash + @database = hash["database"] || hash[:database] + @config = { + "-h" => hash["host"] || hash[:host], + "-u" => hash["username"] || hash[:username], + "-p" => hash["password"] || hash[:password], + "--port=" => hash["port"] || hash[:port], + } + end + + def export_tables(tables) + return if tables.empty? + + self.class.sanitize_sql( + execute("--compact", "--skip-lock-tables", "--single-transaction", "--no-data", + "--column-statistics=0", *tables) + ) + end + + def export_migrations(migrations) + migrations.in_groups_of(50, false).map do |versions| + execute( + "--compact", "--skip-lock-tables", "--single-transaction", + "--no-create-info", "--column-statistics=0", + "schema_migrations", + "-w", "version IN (#{versions.join(',')})" + ) + end.join.gsub(/VALUES /, "VALUES\n").gsub(/,/, ",\n") + end + + private + + def execute(*args) + stdout, stderr, status = Open3.capture3("mysqldump", *connection_args, @database, *args) + raise stderr unless status.success? + + stdout + end + + def connection_args + @config.compact.map do |arg, value| + "#{arg}#{value}" + end + end + end + end +end diff --git a/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb b/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb new file mode 100644 index 00000000..8f027297 --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb @@ -0,0 +1,58 @@ +# rubocop:disable all + +module Edgestitch + module Mysql + class StructureConstraintOrderMunger + class << self + def munge(sql) + start_idx = end_idx = nil + lines = sql.split("\n") + lines.each_with_index do |line, idx| + if line =~ /^\s*CONSTRAINT\b/ + start_idx = idx if start_idx.nil? + elsif start_idx + end_idx = idx - 1 + unless end_idx == start_idx + lines[start_idx..end_idx] = order_and_commafy(lines[start_idx..end_idx]) + end + start_idx = end_idx = nil + end + end + lines.join("\n") + end + + private + + def ends_with_comma(s) + s.rstrip.end_with?(",") + end + + def decommafy(s) + return s unless ends_with_comma(s.rstrip) + "#{s.rstrip[0..-2]}\n" + end + + def commafy(s) + return s if ends_with_comma(s.rstrip) + "#{s.rstrip},\n" + end + + def order_and_commafy(lines) + last_line_should_have_comma = ends_with_comma(lines[-1]) + lines.sort! + # First lines.length-1 lines always need commas + lines[0..-2].each_with_index do |line, idx| + lines[idx] = commafy(line) + end + # Last line may or may not need comma + if last_line_should_have_comma + lines[-1] = commafy(lines[-1]) + else + lines[-1] = decommafy(lines[-1]) + end + lines + end + end + end + end +end diff --git a/packages/edgestitch/lib/edgestitch/railtie.rb b/packages/edgestitch/lib/edgestitch/railtie.rb new file mode 100644 index 00000000..d5e4a6d0 --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/railtie.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "edgestitch" + +module Edgestitch + class Railtie < ::Rails::Railtie + rake_tasks { ::Edgestitch::Tasks.define_create } + end +end diff --git a/packages/edgestitch/lib/edgestitch/renderer.rb b/packages/edgestitch/lib/edgestitch/renderer.rb new file mode 100644 index 00000000..60a43fa0 --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/renderer.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "erb" + +module Edgestitch + # TODO: doc + # @private + class Renderer + def initialize(engines) + @engines = Set.new(engines) + end + + def each_file(&block) + @engines.map { |engine| engine.root.join("db", "structure-self.sql") } + .filter(&:exist?) + .uniq.each(&block) + end + + def self.to_file(engines, file) + File.write(file, new(engines).render) + end + end +end + +erb = ERB.new(File.read(File.join(__dir__, "stitch.sql.erb"))) +erb.def_method(Edgestitch::Renderer, "render()") diff --git a/packages/edgestitch/lib/edgestitch/stitch.sql.erb b/packages/edgestitch/lib/edgestitch/stitch.sql.erb new file mode 100644 index 00000000..29cd8d4c --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/stitch.sql.erb @@ -0,0 +1,10 @@ +CREATE TABLE IF NOT EXISTS `schema_migrations` ( + `version` varchar(255) NOT NULL, + PRIMARY KEY (`version`), + UNIQUE KEY `unique_schema_migrations` (`version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +<% each_file do |file| %> +-- <%= file.realpath %> +<%= file.read %> +<% end %> diff --git a/packages/edgestitch/lib/edgestitch/tasks.rb b/packages/edgestitch/lib/edgestitch/tasks.rb new file mode 100644 index 00000000..28d67456 --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/tasks.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require "rake/tasklib" + +module Edgestitch + # TODO: doc + # @private + module Tasks + class << self + include Rake::DSL + + def define_create(namespace = "db:stitch") + desc "Create structure.sql for an app based on all loaded engines' structure-self.sql" + task namespace => [:environment] do |_task, _args| + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + ::Edgestitch::Renderer.to_file([*::Rails::Engine.subclasses, Rails.application], filename(db_config)) + end + end + + enhance(namespace, "db:prepare", "db:structure:load", "db:schema:load") + end + + def define_self(engine, namespace: "db:stitch", name: engine.engine_name) + desc "Create structure-self.sql for an engine" + task "#{namespace}:#{name}" => [:environment] do |_, _args| + Rails.application.eager_load! + engine&.eager_load! + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + ::Edgestitch::Exporter.export(engine, ::Edgestitch::Mysql::Dump.new(db_config)) + end + end + + enhance("#{namespace}:#{name}", "db:structure:dump", "app:db:structure:dump", "db:schema:dump", + "app:db:schema:dump") + end + + private + + def enhance(with, *tasks) + tasks.each do |enhanced_task| + Rake::Task[enhanced_task].enhance([with]) if Rake::Task.task_defined?(enhanced_task) + end + end + + def filename(db_config) + if ::ActiveRecord::Tasks::DatabaseTasks.respond_to?(:schema_dump_path) + ::ActiveRecord::Tasks::DatabaseTasks.schema_dump_path(db_config, :sql) + else + name = db_config.respond_to?(:name) ? db_config.name : db_config.spec_name + ::ActiveRecord::Tasks::DatabaseTasks.dump_filename(name, :sql) + end + end + end + end +end diff --git a/packages/edgestitch/lib/edgestitch/version.rb b/packages/edgestitch/lib/edgestitch/version.rb new file mode 100644 index 00000000..6cd3f8e0 --- /dev/null +++ b/packages/edgestitch/lib/edgestitch/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Edgestitch + VERSION = "1.0.0" +end diff --git a/packages/edgestitch/spec/dummy/.ruby-version b/packages/edgestitch/spec/dummy/.ruby-version new file mode 100644 index 00000000..80b0e7ef --- /dev/null +++ b/packages/edgestitch/spec/dummy/.ruby-version @@ -0,0 +1 @@ +ruby-2.7.7 diff --git a/packages/edgestitch/spec/dummy/Rakefile b/packages/edgestitch/spec/dummy/Rakefile new file mode 100644 index 00000000..38012519 --- /dev/null +++ b/packages/edgestitch/spec/dummy/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks + +Edgestitch::Tasks.define_self(Marketing::Engine) +Edgestitch::Tasks.define_self(Payroll::Engine) +Edgestitch::Tasks.define_self(Sales::Engine) diff --git a/packages/edgestitch/spec/dummy/app/models/application_record.rb b/packages/edgestitch/spec/dummy/app/models/application_record.rb new file mode 100644 index 00000000..71fbba5b --- /dev/null +++ b/packages/edgestitch/spec/dummy/app/models/application_record.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/packages/edgestitch/spec/dummy/app/models/concerns/.keep b/packages/edgestitch/spec/dummy/app/models/concerns/.keep new file mode 100644 index 00000000..e69de29b diff --git a/packages/edgestitch/spec/dummy/bin/rails b/packages/edgestitch/spec/dummy/bin/rails new file mode 100755 index 00000000..22f2d8de --- /dev/null +++ b/packages/edgestitch/spec/dummy/bin/rails @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/packages/edgestitch/spec/dummy/bin/rake b/packages/edgestitch/spec/dummy/bin/rake new file mode 100755 index 00000000..e436ea54 --- /dev/null +++ b/packages/edgestitch/spec/dummy/bin/rake @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/packages/edgestitch/spec/dummy/bin/setup b/packages/edgestitch/spec/dummy/bin/setup new file mode 100755 index 00000000..5893c4fd --- /dev/null +++ b/packages/edgestitch/spec/dummy/bin/setup @@ -0,0 +1,35 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + puts "\n== Restarting application server ==" + system! "bin/rails restart" +end diff --git a/packages/edgestitch/spec/dummy/config.ru b/packages/edgestitch/spec/dummy/config.ru new file mode 100644 index 00000000..bff88d60 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config.ru @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application diff --git a/packages/edgestitch/spec/dummy/config/application.rb b/packages/edgestitch/spec/dummy/config/application.rb new file mode 100644 index 00000000..2c56fb3c --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/application.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require_relative "boot" + +require "rails/all" + +Bundler.require(*Rails.groups) + +require "edgestitch/railtie" + +require_relative "../engines/marketing/lib/marketing/engine" +require_relative "../engines/payroll/lib/payroll/engine" +require_relative "../engines/sales/lib/sales/engine" + +module Dummy + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 6.0 + + config.active_record.schema_format = :sql + end +end diff --git a/packages/edgestitch/spec/dummy/config/boot.rb b/packages/edgestitch/spec/dummy/config/boot.rb new file mode 100644 index 00000000..59459d4a --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/boot.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Set up gems listed in the Gemfile. +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) + +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) +$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__) diff --git a/packages/edgestitch/spec/dummy/config/cable.yml b/packages/edgestitch/spec/dummy/config/cable.yml new file mode 100644 index 00000000..98367f89 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: dummy_production diff --git a/packages/edgestitch/spec/dummy/config/database.yml b/packages/edgestitch/spec/dummy/config/database.yml new file mode 100644 index 00000000..e9b77a6b --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/database.yml @@ -0,0 +1,29 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: mysql2 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + username: root + password: root + host: 0.0.0.0 + port: 3306 + +development: + <<: *default + database: development + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: test + +production: + <<: *default + database: production diff --git a/packages/edgestitch/spec/dummy/config/environment.rb b/packages/edgestitch/spec/dummy/config/environment.rb new file mode 100644 index 00000000..7df99e89 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/environment.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/packages/edgestitch/spec/dummy/config/environments/development.rb b/packages/edgestitch/spec/dummy/config/environments/development.rb new file mode 100644 index 00000000..8481d26c --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/environments/development.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp", "caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}", + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + # config.assets.debug = true + + # Suppress logger output for asset requests. + # config.assets.quiet = true + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/packages/edgestitch/spec/dummy/config/environments/production.rb b/packages/edgestitch/spec/dummy/config/environments/production.rb new file mode 100644 index 00000000..3eb1ac19 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/environments/production.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [:request_id] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "dummy_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new($stdout) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session +end diff --git a/packages/edgestitch/spec/dummy/config/environments/test.rb b/packages/edgestitch/spec/dummy/config/environments/test.rb new file mode 100644 index 00000000..4d0ffb57 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/environments/test.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + config.cache_classes = false + config.action_view.cache_template_loading = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{1.hour.to_i}", + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true +end diff --git a/packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb b/packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb new file mode 100644 index 00000000..f4556db3 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/packages/edgestitch/spec/dummy/config/initializers/assets.rb b/packages/edgestitch/spec/dummy/config/initializers/assets.rb new file mode 100644 index 00000000..6f260d5c --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/assets.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +# Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb b/packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 00000000..d0f0d3b5 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb b/packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb new file mode 100644 index 00000000..98230c98 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Set the nonce only to specific directives +# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/packages/edgestitch/spec/dummy/config/initializers/cookies_serializer.rb b/packages/edgestitch/spec/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 00000000..ee8dff9c --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/packages/edgestitch/spec/dummy/config/initializers/filter_parameter_logging.rb b/packages/edgestitch/spec/dummy/config/initializers/filter_parameter_logging.rb new file mode 100644 index 00000000..7a4f47b4 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/packages/edgestitch/spec/dummy/config/initializers/inflections.rb b/packages/edgestitch/spec/dummy/config/initializers/inflections.rb new file mode 100644 index 00000000..aa7435fb --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/inflections.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/packages/edgestitch/spec/dummy/config/initializers/mime_types.rb b/packages/edgestitch/spec/dummy/config/initializers/mime_types.rb new file mode 100644 index 00000000..6e1d16f0 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/packages/edgestitch/spec/dummy/config/initializers/wrap_parameters.rb b/packages/edgestitch/spec/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 00000000..2f3c0db4 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/packages/edgestitch/spec/dummy/config/locales/en.yml b/packages/edgestitch/spec/dummy/config/locales/en.yml new file mode 100644 index 00000000..cf9b342d --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/packages/edgestitch/spec/dummy/config/puma.rb b/packages/edgestitch/spec/dummy/config/puma.rb new file mode 100644 index 00000000..f1698ea4 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/puma.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT", 3000) + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV", "development") + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/packages/edgestitch/spec/dummy/config/routes.rb b/packages/edgestitch/spec/dummy/config/routes.rb new file mode 100644 index 00000000..cefb14fb --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/routes.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html +end diff --git a/packages/edgestitch/spec/dummy/config/spring.rb b/packages/edgestitch/spec/dummy/config/spring.rb new file mode 100644 index 00000000..37a35434 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/spring.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +Spring.watch( + ".ruby-version", + ".rbenv-vars", + "tmp/restart.txt", + "tmp/caching-dev.txt" +) diff --git a/packages/edgestitch/spec/dummy/config/storage.yml b/packages/edgestitch/spec/dummy/config/storage.yml new file mode 100644 index 00000000..d32f76e8 --- /dev/null +++ b/packages/edgestitch/spec/dummy/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/packages/edgestitch/spec/dummy/db/structure-self.sql b/packages/edgestitch/spec/dummy/db/structure-self.sql new file mode 100644 index 00000000..b28b04f6 --- /dev/null +++ b/packages/edgestitch/spec/dummy/db/structure-self.sql @@ -0,0 +1,3 @@ + + + diff --git a/packages/edgestitch/spec/dummy/db/structure.sql b/packages/edgestitch/spec/dummy/db/structure.sql new file mode 100644 index 00000000..61a6bb04 --- /dev/null +++ b/packages/edgestitch/spec/dummy/db/structure.sql @@ -0,0 +1,126 @@ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +DROP TABLE IF EXISTS `ar_internal_metadata`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `ar_internal_metadata` ( + `key` varchar(255) NOT NULL, + `value` varchar(255) DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `marketing_leads`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `marketing_leads` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `payroll_salaries`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `payroll_salaries` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `sales_prices`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `sales_prices` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `schema_migrations`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `schema_migrations` ( + `version` varchar(255) NOT NULL, + PRIMARY KEY (`version`), + UNIQUE KEY `unique_schema_migrations` (`version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `taggings`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `taggings` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `tag_id` bigint DEFAULT NULL, + `taggable_type` varchar(255) DEFAULT NULL, + `taggable_id` bigint DEFAULT NULL, + `tagger_type` varchar(255) DEFAULT NULL, + `tagger_id` bigint DEFAULT NULL, + `context` varchar(128) DEFAULT NULL, + `created_at` datetime DEFAULT NULL, + `tenant` varchar(128) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `index_taggings_on_tag_id` (`tag_id`), + KEY `index_taggings_on_taggable_type_and_taggable_id` (`taggable_type`,`taggable_id`), + KEY `index_taggings_on_tagger_type_and_tagger_id` (`tagger_type`,`tagger_id`), + KEY `taggings_taggable_context_idx` (`taggable_id`,`taggable_type`,`context`), + KEY `index_taggings_on_taggable_id` (`taggable_id`), + KEY `index_taggings_on_taggable_type` (`taggable_type`), + KEY `index_taggings_on_tagger_id` (`tagger_id`), + KEY `index_taggings_on_context` (`context`), + KEY `index_taggings_on_tagger_id_and_tagger_type` (`tagger_id`,`tagger_type`), + KEY `taggings_idy` (`taggable_id`,`taggable_type`,`tagger_id`,`context`), + KEY `index_taggings_on_tenant` (`tenant`), + CONSTRAINT `fk_rails_9fcd2e236b` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +DROP TABLE IF EXISTS `tags`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tags` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + `taggings_count` int DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `index_tags_on_name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +INSERT INTO `schema_migrations` (version) VALUES +('20221219191938'), +('20221219195431'), +('20221219203032'), +('20221219231318'), +('20221219231320'), +('20221219231322'), +('20221219231323'), +('20221219231324'); + + diff --git a/packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/application_record.rb b/packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/application_record.rb new file mode 100644 index 00000000..7388ed2e --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/application_record.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Marketing + class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true + end +end diff --git a/packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/lead.rb b/packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/lead.rb new file mode 100644 index 00000000..4726a652 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/marketing/app/models/marketing/lead.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Marketing + class Lead < Marketing::ApplicationRecord + end +end diff --git a/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb b/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb new file mode 100644 index 00000000..72070259 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreateMarketingLeads < ActiveRecord::Migration[7.0] + def change + create_table :marketing_leads do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/marketing/db/structure-self.sql b/packages/edgestitch/spec/dummy/engines/marketing/db/structure-self.sql new file mode 100644 index 00000000..7c5a7784 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/marketing/db/structure-self.sql @@ -0,0 +1,10 @@ +CREATE TABLE `marketing_leads` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219203032'); diff --git a/packages/edgestitch/spec/dummy/engines/marketing/lib/marketing/engine.rb b/packages/edgestitch/spec/dummy/engines/marketing/lib/marketing/engine.rb new file mode 100644 index 00000000..4b112c26 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/marketing/lib/marketing/engine.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Marketing + class Engine < ::Rails::Engine + isolate_namespace ::Marketing + + initializer :append_migrations do |app| + app.config.paths["db/migrate"].push(*config.paths["db/migrate"].expanded) + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/application_record.rb b/packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/application_record.rb new file mode 100644 index 00000000..e495f964 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/application_record.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Payroll + class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/salary.rb b/packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/salary.rb new file mode 100644 index 00000000..250d9bf7 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/app/models/payroll/salary.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Payroll + class Salary < Payroll::ApplicationRecord + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables b/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables new file mode 100644 index 00000000..67f6770c --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables @@ -0,0 +1,2 @@ +tags +taggings diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb new file mode 100644 index 00000000..1a89ec44 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreatePayrollSalaries < ActiveRecord::Migration[7.0] + def change + create_table :payroll_salaries do |t| + t.integer :value + + t.timestamps + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..6f17e06d --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 1) +class ActsAsTaggableOnMigration < ActiveRecord::Migration[6.0] + def self.up # rubocop:disable Metrics/MethodLength + create_table ActsAsTaggableOn.tags_table do |t| + t.string :name + t.timestamps + end + + create_table ActsAsTaggableOn.taggings_table do |t| + t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table } + + # You should make sure that the column created is + # long enough to store the required class names. + t.references :taggable, polymorphic: true + t.references :tagger, polymorphic: true + + # Limit is created to prevent MySQL error on index + # length for MyISAM table type: http://bit.ly/vgW2Ql + t.string :context, limit: 128 + + t.datetime :created_at + end + + add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type context], + name: "taggings_taggable_context_idx" + end + + def self.down + drop_table ActsAsTaggableOn.taggings_table + drop_table ActsAsTaggableOn.tags_table + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..d17afe82 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 3) +class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[6.0] + def self.up + add_column ActsAsTaggableOn.tags_table, :taggings_count, :integer, default: 0 + + ActsAsTaggableOn::Tag.reset_column_information + ActsAsTaggableOn::Tag.find_each do |tag| + ActsAsTaggableOn::Tag.reset_counters(tag.id, ActsAsTaggableOn.taggings_table) + end + end + + def self.down + remove_column ActsAsTaggableOn.tags_table, :taggings_count + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..40de32d5 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 5) +# This migration is added to circumvent issue #623 and have special characters +# work properly + +class ChangeCollationForTagNames < ActiveRecord::Migration[6.0] + def up + return unless ActsAsTaggableOn::Utils.using_mysql? + + execute("ALTER TABLE #{ActsAsTaggableOn.tags_table} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..f6e5b4ae --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 6) +class AddMissingIndexesOnTaggings < ActiveRecord::Migration[6.0] + def change # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize + add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id + add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, + :taggable_id + add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, + :taggable_type + add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, + :tagger_id + add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context + + unless index_exists? ActsAsTaggableOn.taggings_table, %i[tagger_id tagger_type] + add_index ActsAsTaggableOn.taggings_table, %i[tagger_id tagger_type] + end + + unless index_exists? ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type tagger_id context], + name: "taggings_idy" + add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type tagger_id context], + name: "taggings_idy" + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb new file mode 100644 index 00000000..b62b6604 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# This migration comes from acts_as_taggable_on_engine (originally 7) +class AddTenantToTaggings < ActiveRecord::Migration[6.0] + def self.up + add_column ActsAsTaggableOn.taggings_table, :tenant, :string, limit: 128 + add_index ActsAsTaggableOn.taggings_table, :tenant unless index_exists? ActsAsTaggableOn.taggings_table, :tenant + end + + def self.down + remove_index ActsAsTaggableOn.taggings_table, :tenant + remove_column ActsAsTaggableOn.taggings_table, :tenant + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql b/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql new file mode 100644 index 00000000..3c7104b1 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql @@ -0,0 +1,50 @@ +CREATE TABLE `payroll_salaries` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE `tags` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + `taggings_count` int DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `index_tags_on_name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE `taggings` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `tag_id` bigint DEFAULT NULL, + `taggable_type` varchar(255) DEFAULT NULL, + `taggable_id` bigint DEFAULT NULL, + `tagger_type` varchar(255) DEFAULT NULL, + `tagger_id` bigint DEFAULT NULL, + `context` varchar(128) DEFAULT NULL, + `created_at` datetime DEFAULT NULL, + `tenant` varchar(128) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `index_taggings_on_tag_id` (`tag_id`), + KEY `index_taggings_on_taggable_type_and_taggable_id` (`taggable_type`,`taggable_id`), + KEY `index_taggings_on_tagger_type_and_tagger_id` (`tagger_type`,`tagger_id`), + KEY `taggings_taggable_context_idx` (`taggable_id`,`taggable_type`,`context`), + KEY `index_taggings_on_taggable_id` (`taggable_id`), + KEY `index_taggings_on_taggable_type` (`taggable_type`), + KEY `index_taggings_on_tagger_id` (`tagger_id`), + KEY `index_taggings_on_context` (`context`), + KEY `index_taggings_on_tagger_id_and_tagger_type` (`tagger_id`,`tagger_type`), + KEY `taggings_idy` (`taggable_id`,`taggable_type`,`tagger_id`,`context`), + KEY `index_taggings_on_tenant` (`tenant`), + CONSTRAINT `fk_rails_9fcd2e236b` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219195431'), +('20221219231318'), +('20221219231320'), +('20221219231322'), +('20221219231323'), +('20221219231324'); diff --git a/packages/edgestitch/spec/dummy/engines/payroll/lib/payroll/engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/lib/payroll/engine.rb new file mode 100644 index 00000000..1d41377a --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/lib/payroll/engine.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Payroll + class Engine < ::Rails::Engine + isolate_namespace ::Payroll + + initializer :append_migrations do |app| + app.config.paths["db/migrate"].push(*config.paths["db/migrate"].expanded) + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/sales/app/models/sales/application_record.rb b/packages/edgestitch/spec/dummy/engines/sales/app/models/sales/application_record.rb new file mode 100644 index 00000000..3a82b1cc --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/sales/app/models/sales/application_record.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Sales + class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true + end +end diff --git a/packages/edgestitch/spec/dummy/engines/sales/app/models/sales/price.rb b/packages/edgestitch/spec/dummy/engines/sales/app/models/sales/price.rb new file mode 100644 index 00000000..b6dd5327 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/sales/app/models/sales/price.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module Sales + class Price < ::Sales::ApplicationRecord + end +end diff --git a/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb b/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb new file mode 100644 index 00000000..90f41230 --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreateSalesPrices < ActiveRecord::Migration[7.0] + def change + create_table :sales_prices do |t| + t.integer :value + + t.timestamps + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/sales/db/structure-self.sql b/packages/edgestitch/spec/dummy/engines/sales/db/structure-self.sql new file mode 100644 index 00000000..1c55f9cc --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/sales/db/structure-self.sql @@ -0,0 +1,10 @@ +CREATE TABLE `sales_prices` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219191938'); diff --git a/packages/edgestitch/spec/dummy/engines/sales/lib/sales/engine.rb b/packages/edgestitch/spec/dummy/engines/sales/lib/sales/engine.rb new file mode 100644 index 00000000..ed0837ea --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/sales/lib/sales/engine.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Sales + class Engine < ::Rails::Engine + isolate_namespace ::Sales + + initializer :append_migrations do |app| + app.config.paths["db/migrate"].push(*config.paths["db/migrate"].expanded) + end + end +end diff --git a/packages/edgestitch/spec/dummy/lib/assets/.keep b/packages/edgestitch/spec/dummy/lib/assets/.keep new file mode 100644 index 00000000..e69de29b diff --git a/packages/edgestitch/spec/dummy/log/.keep b/packages/edgestitch/spec/dummy/log/.keep new file mode 100644 index 00000000..e69de29b diff --git a/packages/edgestitch/spec/fixtures/files/expected-sales.sql b/packages/edgestitch/spec/fixtures/files/expected-sales.sql new file mode 100644 index 00000000..1c55f9cc --- /dev/null +++ b/packages/edgestitch/spec/fixtures/files/expected-sales.sql @@ -0,0 +1,10 @@ +CREATE TABLE `sales_prices` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219191938'); diff --git a/packages/edgestitch/spec/fixtures/files/expected-structure.sql b/packages/edgestitch/spec/fixtures/files/expected-structure.sql new file mode 100644 index 00000000..119739cb --- /dev/null +++ b/packages/edgestitch/spec/fixtures/files/expected-structure.sql @@ -0,0 +1,86 @@ +CREATE TABLE IF NOT EXISTS `schema_migrations` ( + `version` varchar(255) NOT NULL, + PRIMARY KEY (`version`), + UNIQUE KEY `unique_schema_migrations` (`version`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +-- /Users/chjunior/workspace/power/power-tools/packages/edgestitch/spec/dummy/engines/marketing/db/structure-self.sql +CREATE TABLE `marketing_leads` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219203032'); + + +-- /Users/chjunior/workspace/power/power-tools/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql +CREATE TABLE `payroll_salaries` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE `tags` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + `taggings_count` int DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `index_tags_on_name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +CREATE TABLE `taggings` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `tag_id` bigint DEFAULT NULL, + `taggable_type` varchar(255) DEFAULT NULL, + `taggable_id` bigint DEFAULT NULL, + `tagger_type` varchar(255) DEFAULT NULL, + `tagger_id` bigint DEFAULT NULL, + `context` varchar(128) DEFAULT NULL, + `created_at` datetime DEFAULT NULL, + `tenant` varchar(128) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `index_taggings_on_tag_id` (`tag_id`), + KEY `index_taggings_on_taggable_type_and_taggable_id` (`taggable_type`,`taggable_id`), + KEY `index_taggings_on_tagger_type_and_tagger_id` (`tagger_type`,`tagger_id`), + KEY `taggings_taggable_context_idx` (`taggable_id`,`taggable_type`,`context`), + KEY `index_taggings_on_taggable_id` (`taggable_id`), + KEY `index_taggings_on_taggable_type` (`taggable_type`), + KEY `index_taggings_on_tagger_id` (`tagger_id`), + KEY `index_taggings_on_context` (`context`), + KEY `index_taggings_on_tagger_id_and_tagger_type` (`tagger_id`,`tagger_type`), + KEY `taggings_idy` (`taggable_id`,`taggable_type`,`tagger_id`,`context`), + KEY `index_taggings_on_tenant` (`tenant`), + CONSTRAINT `fk_rails_9fcd2e236b` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219195431'), +('20221219231318'), +('20221219231320'), +('20221219231322'), +('20221219231323'), +('20221219231324'); + + +-- /Users/chjunior/workspace/power/power-tools/packages/edgestitch/spec/dummy/engines/sales/db/structure-self.sql +CREATE TABLE `sales_prices` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `value` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `updated_at` datetime(6) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + +INSERT INTO `schema_migrations` VALUES +('20221219191938'); + + diff --git a/packages/edgestitch/spec/patchwork/exporter_spec.rb b/packages/edgestitch/spec/patchwork/exporter_spec.rb new file mode 100644 index 00000000..97f7e500 --- /dev/null +++ b/packages/edgestitch/spec/patchwork/exporter_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Edgestitch::Exporter do + let(:dump) { double(Edgestitch::Mysql::Dump, export_tables: "tables sql", export_migrations: "migrations sql") } + + it "exports the tables of models owned by the engine" do + exporter = Edgestitch::Exporter.new(Sales::Engine) + output = StringIO.new + + exporter.export(dump, io: output) + + expect(output.string).to eql "tables sql\n\nmigrations sql\n" + end + + it "selects the tables belonging to the given engine" do + exporter = Edgestitch::Exporter.new(Sales::Engine) + + expect(exporter.tables).to match_array %w[sales_prices] + end + + it "includes extra tables owned by the engine" do + exporter = Edgestitch::Exporter.new(Payroll::Engine) + + expect(exporter.tables).to match_array %w[payroll_salaries taggings tags] + end + + it "includes only migrations inside that engine" do + exporter = Edgestitch::Exporter.new(Payroll::Engine) + + expect(exporter.migrations).to match_array [20_221_219_195_431, 20_221_219_231_318, 20_221_219_231_320, + 20_221_219_231_322, 20_221_219_231_323, 20_221_219_231_324] + end +end diff --git a/packages/edgestitch/spec/patchwork/renderer_spec.rb b/packages/edgestitch/spec/patchwork/renderer_spec.rb new file mode 100644 index 00000000..2b1880b7 --- /dev/null +++ b/packages/edgestitch/spec/patchwork/renderer_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe Edgestitch::Renderer do + before do + Rails.application.eager_load! + end + + let(:renderer) { Edgestitch::Renderer.new([Sales::Engine, Payroll::Engine]) } + + it "renders tables from all given components" do + expect(renderer.render).to include("spec/dummy/engines/sales/db/structure-self.sql").once + expect(renderer.render).to include("CREATE TABLE `sales_prices`").once + expect(renderer.render).to include("spec/dummy/engines/payroll/db/structure-self.sql").once + expect(renderer.render).to include("CREATE TABLE `payroll_salaries` (").once + expect(renderer.render).to include("CREATE TABLE `tags` (").once + expect(renderer.render).to include("CREATE TABLE `taggings` (").once + expect(renderer.render).to include("CREATE TABLE").exactly(5).times + end + + it "renders a single schema_migrations table" do + expect(renderer.render).to include("CREATE TABLE IF NOT EXISTS `schema_migrations`").once + end + + it "includes insert statements for the migrations of the given components" do + expect(renderer.render).to include("INSERT INTO `schema_migrations` VALUES").twice + expect(renderer.render).to include("20221219191938").once + expect(renderer.render).to include("20221219195431").once + expect(renderer.render).to include("20221219231318").once + expect(renderer.render).to include("20221219231320").once + expect(renderer.render).to include("20221219231322").once + expect(renderer.render).to include("20221219231323").once + expect(renderer.render).to include("20221219231324").once + end +end diff --git a/packages/edgestitch/spec/patchwork/tasks_spec.rb b/packages/edgestitch/spec/patchwork/tasks_spec.rb new file mode 100644 index 00000000..68a898d2 --- /dev/null +++ b/packages/edgestitch/spec/patchwork/tasks_spec.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +require "rails_helper" + +RAILS_62_ABOVE = Rails.version >= "6.2" + +RSpec.describe Edgestitch::Tasks do + def rake_execute(task, ...) + Rake::Task[task].execute(...) + end + + def dry_run(task, ...) # rubocop:disable Metrics/AbcSize + output = StringIO.new + dryrun = Rake.application.options.dryrun + trace_output = Rake.application.options.trace_output + Rake.application.options.dryrun = true + Rake.application.options.trace_output = output + Rake::Task[task].invoke(...) + output.string + ensure + Rake.application.options.trace_output = trace_output + Rake.application.options.dryrun = dryrun + end + + before(:all) { Rails.application.load_tasks } + + describe ":create" do + it "defines the create task to create a structure.sql" do + expect(Rake::Task).to be_task_defined("db:stitch") + end + + it "renders the structure.sql with all loaded engines" do + expect(Edgestitch::Renderer).to( + receive(:to_file).with( + array_including([Marketing::Engine, Payroll::Engine, Sales::Engine]), + Rails.root.join("db", "structure.sql").to_s + ) + ) + + rake_execute "db:stitch" + end + + describe "rails enhancing" do + it "creates the structure.sql before loading a schema" do + execution = dry_run("db:schema:load") + + expect(execution).to eql <<~OUTPUT + ** Execute (dry run) environment + ** Execute (dry run) db:load_config + ** Execute (dry run) db:check_protected_environments + ** Execute (dry run) db:stitch + ** Execute (dry run) db:schema:load + OUTPUT + end + + it "creates the structure.sql before loading a structure", unless: RAILS_62_ABOVE do + execution = dry_run("db:structure:load") + + expect(execution).to eql <<~OUTPUT + ** Execute (dry run) environment + ** Execute (dry run) db:load_config + ** Execute (dry run) db:check_protected_environments + ** Execute (dry run) db:stitch + ** Execute (dry run) db:structure:load + OUTPUT + end + end + end + + describe ":self" do + before(:all) do + Edgestitch::Tasks.define_self(Sales::Engine, namespace: "db:spec") + end + + it "defines the create task to create a structure-self.sql" do + expect(Rake::Task).to be_task_defined("db:spec:sales") + end + + it "renders the structure-self.sql with engine tables and migrations" do + expect(Edgestitch::Exporter).to( + receive(:export).with( + Sales::Engine, + an_instance_of(Edgestitch::Mysql::Dump) + ) + ) + + rake_execute "db:spec:sales" + end + + describe "rails enhancements" do + it "creates the structure-self.sql when structure dump is called", unless: RAILS_62_ABOVE do + execution = dry_run("db:structure:dump") + + expect(execution).to eql <<~OUTPUT + ** Execute (dry run) db:spec:sales + ** Execute (dry run) db:structure:dump + OUTPUT + end + + it "creates the structure-self.sql when schema dump is called" do + execution = dry_run("db:schema:dump") + + expect(execution).to eql <<~OUTPUT + ** Execute (dry run) db:spec:sales + ** Execute (dry run) db:schema:dump + OUTPUT + end + end + end +end diff --git a/packages/edgestitch/spec/rails_helper.rb b/packages/edgestitch/spec/rails_helper.rb new file mode 100644 index 00000000..96b988a4 --- /dev/null +++ b/packages/edgestitch/spec/rails_helper.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +ENV["RAILS_ENV"] ||= "test" + +# Per SimpleCov documentation, this MUST be required before any appplication code +# https://github.com/colszowka/simplecov#getting-started +unless ENV["SIMPLECOV"] == "false" + require "simplecov" + SimpleCov.start "rails" do + add_filter "/spec" + end +end + +require File.expand_path("dummy/config/environment", __dir__) + +require "rspec/rails" +require "rspec/expectations" + +Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each { |f| require f } + +RSpec.configure do |config| + config.before(:all) { Rails.application.eager_load! } + config.use_transactional_fixtures = true +end diff --git a/packages/edgestitch/spec/spec_helper.rb b/packages/edgestitch/spec/spec_helper.rb new file mode 100644 index 00000000..1d4048fb --- /dev/null +++ b/packages/edgestitch/spec/spec_helper.rb @@ -0,0 +1,98 @@ +# frozen_string_literal: true + +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows you to limit a spec run to individual examples or groups + # # you care about by tagging them with `:focus` metadata. When nothing + # # is tagged with `:focus`, all examples get run. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode + # config.disable_monkey_patching! + # + # # This setting enables warnings. It's recommended, but in some cases may + # # be too noisy due to issues in dependencies. + # config.warnings = true + # + # # Many RSpec users commonly either run the entire suite or an individual + # # file, and it's useful to allow more verbose output when running an + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = "doc" + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # Run specs in random order to surface order dependencies. If you find an + # # order dependency and want to debug it, you can fix the order by providing + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed +end From 0b4149a885c6867baa17015304e00a1356ce8b70 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 20 Dec 2022 22:50:03 -0300 Subject: [PATCH 02/32] Add edgestitch workflow --- .github/workflows/edgestitch.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/edgestitch.yml diff --git a/.github/workflows/edgestitch.yml b/.github/workflows/edgestitch.yml new file mode 100644 index 00000000..915691c1 --- /dev/null +++ b/.github/workflows/edgestitch.yml @@ -0,0 +1,12 @@ +name: edgestitch + +on: + push: + +jobs: + ruby: + uses: ./.github/workflows/_ruby-package.yml + with: + package: ${{ github.workflow }} + workdir: 'packages/${{ github.workflow }}' + secrets: inherit From 1c59f3d3e52b6f79322522686b78dd52c9b786e0 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 20 Dec 2022 22:51:48 -0300 Subject: [PATCH 03/32] Remove Gemfile.lock to support multiple rails versions --- packages/edgestitch/.gitignore | 1 + packages/edgestitch/Gemfile.lock | 257 ------------------------------- 2 files changed, 1 insertion(+), 257 deletions(-) delete mode 100644 packages/edgestitch/Gemfile.lock diff --git a/packages/edgestitch/.gitignore b/packages/edgestitch/.gitignore index 58a53199..94f29716 100644 --- a/packages/edgestitch/.gitignore +++ b/packages/edgestitch/.gitignore @@ -8,3 +8,4 @@ spec/dummy/log/*.log spec/dummy/storage/ spec/dummy/tmp/ coverage +Gemfile.lock diff --git a/packages/edgestitch/Gemfile.lock b/packages/edgestitch/Gemfile.lock deleted file mode 100644 index bfee26af..00000000 --- a/packages/edgestitch/Gemfile.lock +++ /dev/null @@ -1,257 +0,0 @@ -PATH - remote: . - specs: - edgestitch (0.1.0) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.0.4) - actionpack (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activesupport (= 7.0.4) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.4) - actionview (= 7.0.4) - activesupport (= 7.0.4) - rack (~> 2.0, >= 2.2.0) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.4) - actionpack (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) - globalid (>= 0.6.0) - nokogiri (>= 1.8.5) - actionview (7.0.4) - activesupport (= 7.0.4) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.4) - activesupport (= 7.0.4) - globalid (>= 0.3.6) - activemodel (7.0.4) - activesupport (= 7.0.4) - activerecord (7.0.4) - activemodel (= 7.0.4) - activesupport (= 7.0.4) - activestorage (7.0.4) - actionpack (= 7.0.4) - activejob (= 7.0.4) - activerecord (= 7.0.4) - activesupport (= 7.0.4) - marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - acts-as-taggable-on (9.0.1) - activerecord (>= 6.0, < 7.1) - ast (2.4.2) - builder (3.2.4) - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.1.10) - crass (1.0.6) - date (3.3.3) - diff-lcs (1.5.0) - docile (1.1.5) - erubi (1.11.0) - globalid (1.0.0) - activesupport (>= 5.0) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - json (2.6.3) - license_finder (7.1.0) - bundler - rubyzip (>= 1, < 3) - thor (~> 1.2) - tomlrb (>= 1.3, < 2.1) - with_env (= 1.1.0) - xml-simple (~> 1.1.9) - loofah (2.19.1) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.8.0) - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - minitest (5.16.3) - mysql2 (0.5.3) - net-imap (0.3.2) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.2.1) - timeout - net-smtp (0.3.3) - net-protocol - nio4r (2.5.8) - nokogiri (1.13.10-arm64-darwin) - racc (~> 1.4) - parallel (1.22.1) - parser (3.1.3.0) - ast (~> 2.4.1) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - racc (1.6.1) - rack (2.2.4) - rack-test (2.0.2) - rack (>= 1.3) - rails (7.0.4) - actioncable (= 7.0.4) - actionmailbox (= 7.0.4) - actionmailer (= 7.0.4) - actionpack (= 7.0.4) - actiontext (= 7.0.4) - actionview (= 7.0.4) - activejob (= 7.0.4) - activemodel (= 7.0.4) - activerecord (= 7.0.4) - activestorage (= 7.0.4) - activesupport (= 7.0.4) - bundler (>= 1.15.0) - railties (= 7.0.4) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.4) - loofah (~> 2.19, >= 2.19.1) - railties (7.0.4) - actionpack (= 7.0.4) - activesupport (= 7.0.4) - method_source - rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.6.1) - rexml (3.2.5) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.0) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (5.1.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - railties (>= 5.2) - rspec-core (~> 3.10) - rspec-expectations (~> 3.10) - rspec-mocks (~> 3.10) - rspec-support (~> 3.10) - rspec-support (3.12.0) - rubocop (1.40.0) - json (~> 2.3) - parallel (~> 1.10) - parser (>= 3.1.2.1) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.23.0, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.24.0) - parser (>= 3.1.1.0) - rubocop-performance (1.15.1) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - rubocop-powerhome (0.5.0) - rubocop - rubocop-performance - rubocop-rails - rubocop-rake - rubocop-rspec - rubocop-rails (2.17.3) - activesupport (>= 4.2.0) - rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) - rubocop-rake (0.6.0) - rubocop (~> 1.0) - rubocop-rspec (2.16.0) - rubocop (~> 1.33) - ruby-progressbar (1.11.0) - rubyzip (2.3.2) - simplecov (0.15.1) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - thor (1.2.1) - timeout (0.3.1) - tomlrb (2.0.3) - tzinfo (2.0.5) - concurrent-ruby (~> 1.0) - unicode-display_width (2.3.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - with_env (1.1.0) - xml-simple (1.1.9) - rexml - yard (0.9.21) - zeitwerk (2.6.6) - -PLATFORMS - arm64-darwin-22 - -DEPENDENCIES - acts-as-taggable-on (~> 9.0) - bundler (~> 2.1) - license_finder (>= 7.0) - mysql2 (= 0.5.3) - edgestitch! - pry-byebug (= 3.9.0) - rails (>= 5.2.8.1) - rake (~> 13.0) - rspec (~> 3.0) - rspec-rails (~> 5.1.2) - rubocop-powerhome (= 0.5.0) - simplecov (= 0.15.1) - yard (= 0.9.21) - -BUNDLED WITH - 2.3.26 From fda4f38b4e86c0099a34779f4ea1146fa94d4ae0 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 20 Dec 2022 23:13:32 -0300 Subject: [PATCH 04/32] Disable unused frameworks --- .../spec/dummy/config/application.rb | 2 +- .../dummy/config/environments/development.rb | 12 +++++----- .../dummy/config/environments/production.rb | 10 ++++---- .../spec/dummy/config/environments/test.rb | 24 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/edgestitch/spec/dummy/config/application.rb b/packages/edgestitch/spec/dummy/config/application.rb index 2c56fb3c..de30b322 100644 --- a/packages/edgestitch/spec/dummy/config/application.rb +++ b/packages/edgestitch/spec/dummy/config/application.rb @@ -2,7 +2,7 @@ require_relative "boot" -require "rails/all" +require "active_record/railtie" Bundler.require(*Rails.groups) diff --git a/packages/edgestitch/spec/dummy/config/environments/development.rb b/packages/edgestitch/spec/dummy/config/environments/development.rb index 8481d26c..03aeffe3 100644 --- a/packages/edgestitch/spec/dummy/config/environments/development.rb +++ b/packages/edgestitch/spec/dummy/config/environments/development.rb @@ -17,26 +17,26 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join("tmp", "caching-dev.txt").exist? - config.action_controller.perform_caching = true - config.action_controller.enable_fragment_cache_logging = true + # config.action_controller.perform_caching = true + # config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}", } else - config.action_controller.perform_caching = false + # config.action_controller.perform_caching = false config.cache_store = :null_store end # Store uploaded files on the local file system (see config/storage.yml for options). - config.active_storage.service = :local + # config.active_storage.service = :local # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false + # config.action_mailer.raise_delivery_errors = false - config.action_mailer.perform_caching = false + # config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log diff --git a/packages/edgestitch/spec/dummy/config/environments/production.rb b/packages/edgestitch/spec/dummy/config/environments/production.rb index 3eb1ac19..acad92b2 100644 --- a/packages/edgestitch/spec/dummy/config/environments/production.rb +++ b/packages/edgestitch/spec/dummy/config/environments/production.rb @@ -13,8 +13,8 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true + config.consider_all_requests_local = false + # config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). @@ -31,14 +31,14 @@ config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + config.action_controller.asset_host = "http://assets.example.com" # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). - config.active_storage.service = :local + # config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil @@ -62,7 +62,7 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "dummy_production" - config.action_mailer.perform_caching = false + # config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. diff --git a/packages/edgestitch/spec/dummy/config/environments/test.rb b/packages/edgestitch/spec/dummy/config/environments/test.rb index 4d0ffb57..795332d2 100644 --- a/packages/edgestitch/spec/dummy/config/environments/test.rb +++ b/packages/edgestitch/spec/dummy/config/environments/test.rb @@ -9,7 +9,7 @@ # Settings specified here will take precedence over those in config/application.rb. config.cache_classes = false - config.action_view.cache_template_loading = true + # config.action_view.cache_template_loading = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that @@ -17,31 +17,31 @@ config.eager_load = false # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}", - } + # config.public_file_server.enabled = true + # config.public_file_server.headers = { + # "Cache-Control" => "public, max-age=#{1.hour.to_i}", + # } # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + config.consider_all_requests_local = true + # config.action_controller.perform_caching = false config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + # config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. - config.action_controller.allow_forgery_protection = false + # config.action_controller.allow_forgery_protection = false # Store uploaded files on the local file system in a temporary directory. - config.active_storage.service = :test + # config.active_storage.service = :test - config.action_mailer.perform_caching = false + # config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test + # config.action_mailer.delivery_method = :test # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr From 9981c3e012c72fc5f32b5cce6e0f90823d11a726 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 20 Dec 2022 23:22:22 -0300 Subject: [PATCH 05/32] Start mysql on edgestitch workflow --- .github/workflows/edgestitch.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/edgestitch.yml b/.github/workflows/edgestitch.yml index 915691c1..b12edc74 100644 --- a/.github/workflows/edgestitch.yml +++ b/.github/workflows/edgestitch.yml @@ -9,4 +9,5 @@ jobs: with: package: ${{ github.workflow }} workdir: 'packages/${{ github.workflow }}' + before_build: sudo /etc/init.d/mysql start secrets: inherit From 0600d027d411a2dae7c365155b6878d6232579b9 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 01:32:54 -0300 Subject: [PATCH 06/32] Eager load in test to avoid eager loading every where --- .../dummy/config/environments/development.rb | 56 +-------- .../dummy/config/environments/production.rb | 114 ------------------ .../spec/dummy/config/environments/test.rb | 43 +------ packages/edgestitch/spec/rails_helper.rb | 1 - 4 files changed, 3 insertions(+), 211 deletions(-) delete mode 100644 packages/edgestitch/spec/dummy/config/environments/production.rb diff --git a/packages/edgestitch/spec/dummy/config/environments/development.rb b/packages/edgestitch/spec/dummy/config/environments/development.rb index 03aeffe3..61931e5d 100644 --- a/packages/edgestitch/spec/dummy/config/environments/development.rb +++ b/packages/edgestitch/spec/dummy/config/environments/development.rb @@ -1,64 +1,10 @@ # frozen_string_literal: true Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. config.cache_classes = false - - # Do not eager load code on boot. config.eager_load = false - - # Show full error reports. - config.consider_all_requests_local = true - - # Enable/disable caching. By default caching is disabled. - # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp", "caching-dev.txt").exist? - # config.action_controller.perform_caching = true - # config.action_controller.enable_fragment_cache_logging = true - - config.cache_store = :memory_store - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}", - } - else - # config.action_controller.perform_caching = false - - config.cache_store = :null_store - end - - # Store uploaded files on the local file system (see config/storage.yml for options). - # config.active_storage.service = :local - - # Don't care if the mailer can't send. - # config.action_mailer.raise_delivery_errors = false - - # config.action_mailer.perform_caching = false - - # Print deprecation notices to the Rails logger. + config.cache_store = :null_store config.active_support.deprecation = :log - - # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load - - # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - # config.assets.debug = true - - # Suppress logger output for asset requests. - # config.assets.quiet = true - - # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true - - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/packages/edgestitch/spec/dummy/config/environments/production.rb b/packages/edgestitch/spec/dummy/config/environments/production.rb deleted file mode 100644 index acad92b2..00000000 --- a/packages/edgestitch/spec/dummy/config/environments/production.rb +++ /dev/null @@ -1,114 +0,0 @@ -# frozen_string_literal: true - -Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # Code is not reloaded between requests. - config.cache_classes = true - - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both threaded web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. - config.eager_load = true - - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - # config.action_controller.perform_caching = true - - # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). - # config.require_master_key = true - - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? - - # Compress CSS using a preprocessor. - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false - - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - config.action_controller.asset_host = "http://assets.example.com" - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - - # Store uploaded files on the local file system (see config/storage.yml for options). - # config.active_storage.service = :local - - # Mount Action Cable outside main process or domain. - # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true - - # Use the lowest log level to ensure availability of diagnostic information - # when problems arise. - config.log_level = :debug - - # Prepend all log lines with the following tags. - config.log_tags = [:request_id] - - # Use a different cache store in production. - # config.cache_store = :mem_cache_store - - # Use a real queuing backend for Active Job (and separate queues per environment). - # config.active_job.queue_adapter = :resque - # config.active_job.queue_name_prefix = "dummy_production" - - # config.action_mailer.perform_caching = false - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation cannot be found). - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = Logger::Formatter.new - - # Use a different logger for distributed setups. - # require 'syslog/logger' - # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new($stdout) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - - # Do not dump schema after migrations. - config.active_record.dump_schema_after_migration = false - - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session -end diff --git a/packages/edgestitch/spec/dummy/config/environments/test.rb b/packages/edgestitch/spec/dummy/config/environments/test.rb index 795332d2..262897df 100644 --- a/packages/edgestitch/spec/dummy/config/environments/test.rb +++ b/packages/edgestitch/spec/dummy/config/environments/test.rb @@ -6,46 +6,7 @@ # and recreated between test runs. Don't rely on the data there! Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - config.cache_classes = false - # config.action_view.cache_template_loading = true - - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false - - # Configure public file server for tests with Cache-Control for performance. - # config.public_file_server.enabled = true - # config.public_file_server.headers = { - # "Cache-Control" => "public, max-age=#{1.hour.to_i}", - # } - - # Show full error reports and disable caching. - config.consider_all_requests_local = true - # config.action_controller.perform_caching = false - config.cache_store = :null_store - - # Raise exceptions instead of rendering exception templates. - # config.action_dispatch.show_exceptions = false - - # Disable request forgery protection in test environment. - # config.action_controller.allow_forgery_protection = false - - # Store uploaded files on the local file system in a temporary directory. - # config.active_storage.service = :test - - # config.action_mailer.perform_caching = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - # config.action_mailer.delivery_method = :test - - # Print deprecation notices to the stderr. + config.cache_classes = true + config.eager_load = true config.active_support.deprecation = :stderr - - # Raises error for missing translations. - # config.action_view.raise_on_missing_translations = true end diff --git a/packages/edgestitch/spec/rails_helper.rb b/packages/edgestitch/spec/rails_helper.rb index 96b988a4..3be9fb54 100644 --- a/packages/edgestitch/spec/rails_helper.rb +++ b/packages/edgestitch/spec/rails_helper.rb @@ -19,6 +19,5 @@ Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each { |f| require f } RSpec.configure do |config| - config.before(:all) { Rails.application.eager_load! } config.use_transactional_fixtures = true end From 79b6a979a77df6ce38584194b71367617b13a429 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 10:27:20 -0300 Subject: [PATCH 07/32] Expect inclusion to be able to match different rails versions --- packages/edgestitch/spec/patchwork/tasks_spec.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/edgestitch/spec/patchwork/tasks_spec.rb b/packages/edgestitch/spec/patchwork/tasks_spec.rb index 68a898d2..5536db14 100644 --- a/packages/edgestitch/spec/patchwork/tasks_spec.rb +++ b/packages/edgestitch/spec/patchwork/tasks_spec.rb @@ -44,10 +44,7 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize it "creates the structure.sql before loading a schema" do execution = dry_run("db:schema:load") - expect(execution).to eql <<~OUTPUT - ** Execute (dry run) environment - ** Execute (dry run) db:load_config - ** Execute (dry run) db:check_protected_environments + expect(execution).to include <<~OUTPUT ** Execute (dry run) db:stitch ** Execute (dry run) db:schema:load OUTPUT @@ -56,10 +53,7 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize it "creates the structure.sql before loading a structure", unless: RAILS_62_ABOVE do execution = dry_run("db:structure:load") - expect(execution).to eql <<~OUTPUT - ** Execute (dry run) environment - ** Execute (dry run) db:load_config - ** Execute (dry run) db:check_protected_environments + expect(execution).to include <<~OUTPUT ** Execute (dry run) db:stitch ** Execute (dry run) db:structure:load OUTPUT @@ -91,7 +85,7 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize it "creates the structure-self.sql when structure dump is called", unless: RAILS_62_ABOVE do execution = dry_run("db:structure:dump") - expect(execution).to eql <<~OUTPUT + expect(execution).to include <<~OUTPUT ** Execute (dry run) db:spec:sales ** Execute (dry run) db:structure:dump OUTPUT @@ -100,7 +94,7 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize it "creates the structure-self.sql when schema dump is called" do execution = dry_run("db:schema:dump") - expect(execution).to eql <<~OUTPUT + expect(execution).to include <<~OUTPUT ** Execute (dry run) db:spec:sales ** Execute (dry run) db:schema:dump OUTPUT From c43855c2884d1cc67b35c0466c3a5f3333e546bd Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 10:57:29 -0300 Subject: [PATCH 08/32] Allow define_create and define_self return the created task --- packages/edgestitch/lib/edgestitch/tasks.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/edgestitch/lib/edgestitch/tasks.rb b/packages/edgestitch/lib/edgestitch/tasks.rb index 28d67456..d80a555a 100644 --- a/packages/edgestitch/lib/edgestitch/tasks.rb +++ b/packages/edgestitch/lib/edgestitch/tasks.rb @@ -10,36 +10,35 @@ class << self include Rake::DSL def define_create(namespace = "db:stitch") + enhance(namespace, "db:prepare", "db:structure:load", "db:schema:load") desc "Create structure.sql for an app based on all loaded engines' structure-self.sql" task namespace => [:environment] do |_task, _args| ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| ::Edgestitch::Renderer.to_file([*::Rails::Engine.subclasses, Rails.application], filename(db_config)) end end - - enhance(namespace, "db:prepare", "db:structure:load", "db:schema:load") end def define_self(engine, namespace: "db:stitch", name: engine.engine_name) + enhance("#{namespace}:#{name}", "db:structure:dump", "app:db:structure:dump", "db:schema:dump", + "app:db:schema:dump") + desc "Create structure-self.sql for an engine" task "#{namespace}:#{name}" => [:environment] do |_, _args| Rails.application.eager_load! engine&.eager_load! + # puts *caller ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| ::Edgestitch::Exporter.export(engine, ::Edgestitch::Mysql::Dump.new(db_config)) end end - - enhance("#{namespace}:#{name}", "db:structure:dump", "app:db:structure:dump", "db:schema:dump", - "app:db:schema:dump") end private def enhance(with, *tasks) - tasks.each do |enhanced_task| - Rake::Task[enhanced_task].enhance([with]) if Rake::Task.task_defined?(enhanced_task) - end + tasks.filter { |task| Rake::Task.task_defined?(task) } + .each { |task| Rake::Task[task].enhance([with]) } end def filename(db_config) From f0d100546224c675ff62ac26c75df9d62169b4ff Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 10:57:44 -0300 Subject: [PATCH 09/32] Reenable tasks so they can run on a subsequent spec --- packages/edgestitch/spec/patchwork/tasks_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/edgestitch/spec/patchwork/tasks_spec.rb b/packages/edgestitch/spec/patchwork/tasks_spec.rb index 5536db14..042ccbb2 100644 --- a/packages/edgestitch/spec/patchwork/tasks_spec.rb +++ b/packages/edgestitch/spec/patchwork/tasks_spec.rb @@ -22,9 +22,10 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize Rake.application.options.dryrun = dryrun end - before(:all) { Rails.application.load_tasks } - describe ":create" do + before(:all) { Rails.application.load_tasks } + before { Rake::Task["db:stitch"].reenable } + it "defines the create task to create a structure.sql" do expect(Rake::Task).to be_task_defined("db:stitch") end @@ -62,9 +63,8 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize end describe ":self" do - before(:all) do - Edgestitch::Tasks.define_self(Sales::Engine, namespace: "db:spec") - end + before(:all) { Edgestitch::Tasks.define_self(Sales::Engine, namespace: "db:spec") } + before { Rake::Task["db:spec:sales"].reenable } it "defines the create task to create a structure-self.sql" do expect(Rake::Task).to be_task_defined("db:spec:sales") From 52fce8e831086b022bda1de2c54f53a29fcf30e3 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:18:56 -0300 Subject: [PATCH 10/32] Always run tests in RAILS_ENV test --- .github/workflows/_ruby-package.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/_ruby-package.yml b/.github/workflows/_ruby-package.yml index d1f41b05..0e9e58ba 100644 --- a/.github/workflows/_ruby-package.yml +++ b/.github/workflows/_ruby-package.yml @@ -53,6 +53,7 @@ jobs: bundler: '1' env: RAILS_VERSION: '~> ${{ matrix.rails }}' + RAILS_ENV: test steps: - uses: actions/checkout@v3 - name: Set up Ruby From e463efdcd7d19b6abade1a4ad97404eea06f0bff Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:19:21 -0300 Subject: [PATCH 11/32] Prefer configuration_hash to avoid DEPRECATION warning --- packages/edgestitch/lib/edgestitch/mysql/dump.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edgestitch/lib/edgestitch/mysql/dump.rb b/packages/edgestitch/lib/edgestitch/mysql/dump.rb index cd559604..2cebca66 100644 --- a/packages/edgestitch/lib/edgestitch/mysql/dump.rb +++ b/packages/edgestitch/lib/edgestitch/mysql/dump.rb @@ -21,7 +21,7 @@ def self.sanitize_sql(sql) end def initialize(config) - hash = config.respond_to?(:config) ? config.config : config.configuration_hash + hash = config.respond_to?(:configuration_hash) ? config.configuration_hash : config.config @database = hash["database"] || hash[:database] @config = { "-h" => hash["host"] || hash[:host], From a06259fa9ac5e40cea52c9397930cc7878a5e70d Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:19:35 -0300 Subject: [PATCH 12/32] Support psych 4 on ruby 3.1 --- .../edgestitch/spec/dummy/config/cable.yml | 10 ------ .../edgestitch/spec/dummy/config/database.yml | 26 +++++--------- .../edgestitch/spec/dummy/config/storage.yml | 34 ------------------- 3 files changed, 8 insertions(+), 62 deletions(-) delete mode 100644 packages/edgestitch/spec/dummy/config/cable.yml delete mode 100644 packages/edgestitch/spec/dummy/config/storage.yml diff --git a/packages/edgestitch/spec/dummy/config/cable.yml b/packages/edgestitch/spec/dummy/config/cable.yml deleted file mode 100644 index 98367f89..00000000 --- a/packages/edgestitch/spec/dummy/config/cable.yml +++ /dev/null @@ -1,10 +0,0 @@ -development: - adapter: async - -test: - adapter: test - -production: - adapter: redis - url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> - channel_prefix: dummy_production diff --git a/packages/edgestitch/spec/dummy/config/database.yml b/packages/edgestitch/spec/dummy/config/database.yml index e9b77a6b..ce6b6c1f 100644 --- a/packages/edgestitch/spec/dummy/config/database.yml +++ b/packages/edgestitch/spec/dummy/config/database.yml @@ -1,10 +1,4 @@ -# SQLite. Versions 3.8.0 and up are supported. -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# -default: &default +development: adapter: mysql2 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 @@ -12,18 +6,14 @@ default: &default password: root host: 0.0.0.0 port: 3306 - -development: - <<: *default database: development -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: - <<: *default + adapter: mysql2 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + username: root + password: root + host: 0.0.0.0 + port: 3306 database: test - -production: - <<: *default - database: production diff --git a/packages/edgestitch/spec/dummy/config/storage.yml b/packages/edgestitch/spec/dummy/config/storage.yml deleted file mode 100644 index d32f76e8..00000000 --- a/packages/edgestitch/spec/dummy/config/storage.yml +++ /dev/null @@ -1,34 +0,0 @@ -test: - service: Disk - root: <%= Rails.root.join("tmp/storage") %> - -local: - service: Disk - root: <%= Rails.root.join("storage") %> - -# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) -# amazon: -# service: S3 -# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> -# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> -# region: us-east-1 -# bucket: your_own_bucket - -# Remember not to checkin your GCS keyfile to a repository -# google: -# service: GCS -# project: your_project -# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> -# bucket: your_own_bucket - -# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) -# microsoft: -# service: AzureStorage -# storage_account_name: your_account_name -# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> -# container: your_container_name - -# mirror: -# service: Mirror -# primary: local -# mirrors: [ amazon, google, microsoft ] From 91a9467904f724cc6141a652fbdecc6cf9d0bbd4 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:21:22 -0300 Subject: [PATCH 13/32] Inherit dependency decisions from oss-guide --- packages/edgestitch/doc/dependency_decisions.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packages/edgestitch/doc/dependency_decisions.yml diff --git a/packages/edgestitch/doc/dependency_decisions.yml b/packages/edgestitch/doc/dependency_decisions.yml new file mode 100644 index 00000000..f734baa9 --- /dev/null +++ b/packages/edgestitch/doc/dependency_decisions.yml @@ -0,0 +1,3 @@ +--- +- - :inherit_from + - https://raw.githubusercontent.com/powerhome/oss-guide/master/license_rules.yml From fb1430928e460a3f9eddc69ac5326b3942da1c54 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:31:33 -0300 Subject: [PATCH 14/32] Ignore generated structure.sql --- packages/edgestitch/.gitignore | 4 +- .../edgestitch/spec/dummy/db/structure.sql | 126 ------------------ 2 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 packages/edgestitch/spec/dummy/db/structure.sql diff --git a/packages/edgestitch/.gitignore b/packages/edgestitch/.gitignore index 94f29716..a405a882 100644 --- a/packages/edgestitch/.gitignore +++ b/packages/edgestitch/.gitignore @@ -1,9 +1,7 @@ .bundle/ log/*.log pkg/ -spec/dummy/db/*.sqlite3 -spec/dummy/db/*.sqlite3-journal -spec/dummy/db/*.sqlite3-* +spec/dummy/db/structure.sql spec/dummy/log/*.log spec/dummy/storage/ spec/dummy/tmp/ diff --git a/packages/edgestitch/spec/dummy/db/structure.sql b/packages/edgestitch/spec/dummy/db/structure.sql deleted file mode 100644 index 61a6bb04..00000000 --- a/packages/edgestitch/spec/dummy/db/structure.sql +++ /dev/null @@ -1,126 +0,0 @@ - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!50503 SET NAMES utf8mb4 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -DROP TABLE IF EXISTS `ar_internal_metadata`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `ar_internal_metadata` ( - `key` varchar(255) NOT NULL, - `value` varchar(255) DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `updated_at` datetime(6) NOT NULL, - PRIMARY KEY (`key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `marketing_leads`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `marketing_leads` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `name` varchar(255) DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `updated_at` datetime(6) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `payroll_salaries`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `payroll_salaries` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `value` int DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `updated_at` datetime(6) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `sales_prices`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `sales_prices` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `value` int DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `updated_at` datetime(6) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `schema_migrations`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `schema_migrations` ( - `version` varchar(255) NOT NULL, - PRIMARY KEY (`version`), - UNIQUE KEY `unique_schema_migrations` (`version`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `taggings`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `taggings` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `tag_id` bigint DEFAULT NULL, - `taggable_type` varchar(255) DEFAULT NULL, - `taggable_id` bigint DEFAULT NULL, - `tagger_type` varchar(255) DEFAULT NULL, - `tagger_id` bigint DEFAULT NULL, - `context` varchar(128) DEFAULT NULL, - `created_at` datetime DEFAULT NULL, - `tenant` varchar(128) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `index_taggings_on_tag_id` (`tag_id`), - KEY `index_taggings_on_taggable_type_and_taggable_id` (`taggable_type`,`taggable_id`), - KEY `index_taggings_on_tagger_type_and_tagger_id` (`tagger_type`,`tagger_id`), - KEY `taggings_taggable_context_idx` (`taggable_id`,`taggable_type`,`context`), - KEY `index_taggings_on_taggable_id` (`taggable_id`), - KEY `index_taggings_on_taggable_type` (`taggable_type`), - KEY `index_taggings_on_tagger_id` (`tagger_id`), - KEY `index_taggings_on_context` (`context`), - KEY `index_taggings_on_tagger_id_and_tagger_type` (`tagger_id`,`tagger_type`), - KEY `taggings_idy` (`taggable_id`,`taggable_type`,`tagger_id`,`context`), - KEY `index_taggings_on_tenant` (`tenant`), - CONSTRAINT `fk_rails_9fcd2e236b` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -DROP TABLE IF EXISTS `tags`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `tags` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `updated_at` datetime(6) NOT NULL, - `taggings_count` int DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE KEY `index_tags_on_name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - -INSERT INTO `schema_migrations` (version) VALUES -('20221219191938'), -('20221219195431'), -('20221219203032'), -('20221219231318'), -('20221219231320'), -('20221219231322'), -('20221219231323'), -('20221219231324'); - - From 1587fc3b6edf96aa22bbd37865acb6753a92eeb8 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:36:52 -0300 Subject: [PATCH 15/32] Replace acts_as_taggable by table without a model on example --- packages/edgestitch/edgestitch.gemspec | 1 - .../dummy/engines/payroll/db/extra_tables | 3 +- ...on_migration.acts_as_taggable_on_engine.rb | 34 ---------------- ...ache_to_tags.acts_as_taggable_on_engine.rb | 17 -------- ...or_tag_names.acts_as_taggable_on_engine.rb | 13 ------- ..._on_taggings.acts_as_taggable_on_engine.rb | 25 ------------ ..._to_taggings.acts_as_taggable_on_engine.rb | 14 ------- .../20221221142539_create_payroll_ghosts.rb | 11 ++++++ .../engines/payroll/db/structure-self.sql | 39 ++----------------- .../spec/patchwork/exporter_spec.rb | 5 +-- .../spec/patchwork/renderer_spec.rb | 28 ++++++------- 11 files changed, 30 insertions(+), 160 deletions(-) delete mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb delete mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb delete mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb delete mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb delete mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb create mode 100644 packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb diff --git a/packages/edgestitch/edgestitch.gemspec b/packages/edgestitch/edgestitch.gemspec index 76a88153..a891adcb 100644 --- a/packages/edgestitch/edgestitch.gemspec +++ b/packages/edgestitch/edgestitch.gemspec @@ -32,7 +32,6 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_development_dependency "acts-as-taggable-on", "~> 9.0" spec.add_development_dependency "bundler", "~> 2.1" spec.add_development_dependency "license_finder", ">= 7.0" spec.add_development_dependency "mysql2", "0.5.3" diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables b/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables index 67f6770c..6cc47c62 100644 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/extra_tables @@ -1,2 +1 @@ -tags -taggings +payroll_ghosts diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb deleted file mode 100644 index 6f17e06d..00000000 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231318_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -# This migration comes from acts_as_taggable_on_engine (originally 1) -class ActsAsTaggableOnMigration < ActiveRecord::Migration[6.0] - def self.up # rubocop:disable Metrics/MethodLength - create_table ActsAsTaggableOn.tags_table do |t| - t.string :name - t.timestamps - end - - create_table ActsAsTaggableOn.taggings_table do |t| - t.references :tag, foreign_key: { to_table: ActsAsTaggableOn.tags_table } - - # You should make sure that the column created is - # long enough to store the required class names. - t.references :taggable, polymorphic: true - t.references :tagger, polymorphic: true - - # Limit is created to prevent MySQL error on index - # length for MyISAM table type: http://bit.ly/vgW2Ql - t.string :context, limit: 128 - - t.datetime :created_at - end - - add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type context], - name: "taggings_taggable_context_idx" - end - - def self.down - drop_table ActsAsTaggableOn.taggings_table - drop_table ActsAsTaggableOn.tags_table - end -end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb deleted file mode 100644 index d17afe82..00000000 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231320_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -# This migration comes from acts_as_taggable_on_engine (originally 3) -class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[6.0] - def self.up - add_column ActsAsTaggableOn.tags_table, :taggings_count, :integer, default: 0 - - ActsAsTaggableOn::Tag.reset_column_information - ActsAsTaggableOn::Tag.find_each do |tag| - ActsAsTaggableOn::Tag.reset_counters(tag.id, ActsAsTaggableOn.taggings_table) - end - end - - def self.down - remove_column ActsAsTaggableOn.tags_table, :taggings_count - end -end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb deleted file mode 100644 index 40de32d5..00000000 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231322_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# This migration comes from acts_as_taggable_on_engine (originally 5) -# This migration is added to circumvent issue #623 and have special characters -# work properly - -class ChangeCollationForTagNames < ActiveRecord::Migration[6.0] - def up - return unless ActsAsTaggableOn::Utils.using_mysql? - - execute("ALTER TABLE #{ActsAsTaggableOn.tags_table} MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;") - end -end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb deleted file mode 100644 index f6e5b4ae..00000000 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231323_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -# This migration comes from acts_as_taggable_on_engine (originally 6) -class AddMissingIndexesOnTaggings < ActiveRecord::Migration[6.0] - def change # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize - add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id - add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, - :taggable_id - add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, - :taggable_type - add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, - :tagger_id - add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context - - unless index_exists? ActsAsTaggableOn.taggings_table, %i[tagger_id tagger_type] - add_index ActsAsTaggableOn.taggings_table, %i[tagger_id tagger_type] - end - - unless index_exists? ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type tagger_id context], - name: "taggings_idy" - add_index ActsAsTaggableOn.taggings_table, %i[taggable_id taggable_type tagger_id context], - name: "taggings_idy" - end - end -end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb deleted file mode 100644 index b62b6604..00000000 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219231324_add_tenant_to_taggings.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# This migration comes from acts_as_taggable_on_engine (originally 7) -class AddTenantToTaggings < ActiveRecord::Migration[6.0] - def self.up - add_column ActsAsTaggableOn.taggings_table, :tenant, :string, limit: 128 - add_index ActsAsTaggableOn.taggings_table, :tenant unless index_exists? ActsAsTaggableOn.taggings_table, :tenant - end - - def self.down - remove_index ActsAsTaggableOn.taggings_table, :tenant - remove_column ActsAsTaggableOn.taggings_table, :tenant - end -end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb new file mode 100644 index 00000000..15e177cd --- /dev/null +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class CreatePayrollGhosts < ActiveRecord::Migration[5.2] + def change + create_table :payroll_ghosts do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql b/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql index 3c7104b1..1d2db1ef 100644 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/structure-self.sql @@ -6,45 +6,14 @@ CREATE TABLE `payroll_salaries` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -CREATE TABLE `tags` ( +CREATE TABLE `payroll_ghosts` ( `id` bigint NOT NULL AUTO_INCREMENT, - `name` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, `created_at` datetime(6) NOT NULL, `updated_at` datetime(6) NOT NULL, - `taggings_count` int DEFAULT '0', - PRIMARY KEY (`id`), - UNIQUE KEY `index_tags_on_name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - -CREATE TABLE `taggings` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `tag_id` bigint DEFAULT NULL, - `taggable_type` varchar(255) DEFAULT NULL, - `taggable_id` bigint DEFAULT NULL, - `tagger_type` varchar(255) DEFAULT NULL, - `tagger_id` bigint DEFAULT NULL, - `context` varchar(128) DEFAULT NULL, - `created_at` datetime DEFAULT NULL, - `tenant` varchar(128) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `index_taggings_on_tag_id` (`tag_id`), - KEY `index_taggings_on_taggable_type_and_taggable_id` (`taggable_type`,`taggable_id`), - KEY `index_taggings_on_tagger_type_and_tagger_id` (`tagger_type`,`tagger_id`), - KEY `taggings_taggable_context_idx` (`taggable_id`,`taggable_type`,`context`), - KEY `index_taggings_on_taggable_id` (`taggable_id`), - KEY `index_taggings_on_taggable_type` (`taggable_type`), - KEY `index_taggings_on_tagger_id` (`tagger_id`), - KEY `index_taggings_on_context` (`context`), - KEY `index_taggings_on_tagger_id_and_tagger_type` (`tagger_id`,`tagger_type`), - KEY `taggings_idy` (`taggable_id`,`taggable_type`,`tagger_id`,`context`), - KEY `index_taggings_on_tenant` (`tenant`), - CONSTRAINT `fk_rails_9fcd2e236b` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; INSERT INTO `schema_migrations` VALUES ('20221219195431'), -('20221219231318'), -('20221219231320'), -('20221219231322'), -('20221219231323'), -('20221219231324'); +('20221221142539'); diff --git a/packages/edgestitch/spec/patchwork/exporter_spec.rb b/packages/edgestitch/spec/patchwork/exporter_spec.rb index 97f7e500..3d3455ac 100644 --- a/packages/edgestitch/spec/patchwork/exporter_spec.rb +++ b/packages/edgestitch/spec/patchwork/exporter_spec.rb @@ -23,13 +23,12 @@ it "includes extra tables owned by the engine" do exporter = Edgestitch::Exporter.new(Payroll::Engine) - expect(exporter.tables).to match_array %w[payroll_salaries taggings tags] + expect(exporter.tables).to match_array %w[payroll_salaries payroll_ghosts] end it "includes only migrations inside that engine" do exporter = Edgestitch::Exporter.new(Payroll::Engine) - expect(exporter.migrations).to match_array [20_221_219_195_431, 20_221_219_231_318, 20_221_219_231_320, - 20_221_219_231_322, 20_221_219_231_323, 20_221_219_231_324] + expect(exporter.migrations).to match_array [20_221_219_195_431, 20_221_221_142_539] end end diff --git a/packages/edgestitch/spec/patchwork/renderer_spec.rb b/packages/edgestitch/spec/patchwork/renderer_spec.rb index 2b1880b7..6fe04c11 100644 --- a/packages/edgestitch/spec/patchwork/renderer_spec.rb +++ b/packages/edgestitch/spec/patchwork/renderer_spec.rb @@ -8,29 +8,25 @@ end let(:renderer) { Edgestitch::Renderer.new([Sales::Engine, Payroll::Engine]) } + subject { renderer.render } it "renders tables from all given components" do - expect(renderer.render).to include("spec/dummy/engines/sales/db/structure-self.sql").once - expect(renderer.render).to include("CREATE TABLE `sales_prices`").once - expect(renderer.render).to include("spec/dummy/engines/payroll/db/structure-self.sql").once - expect(renderer.render).to include("CREATE TABLE `payroll_salaries` (").once - expect(renderer.render).to include("CREATE TABLE `tags` (").once - expect(renderer.render).to include("CREATE TABLE `taggings` (").once - expect(renderer.render).to include("CREATE TABLE").exactly(5).times + expect(subject).to include("spec/dummy/engines/sales/db/structure-self.sql").once + expect(subject).to include("CREATE TABLE `sales_prices`").once + expect(subject).to include("spec/dummy/engines/payroll/db/structure-self.sql").once + expect(subject).to include("CREATE TABLE `payroll_salaries` (").once + expect(subject).to include("CREATE TABLE `payroll_ghosts` (").once + expect(subject).to include("CREATE TABLE").exactly(4).times end it "renders a single schema_migrations table" do - expect(renderer.render).to include("CREATE TABLE IF NOT EXISTS `schema_migrations`").once + expect(subject).to include("CREATE TABLE IF NOT EXISTS `schema_migrations`").once end it "includes insert statements for the migrations of the given components" do - expect(renderer.render).to include("INSERT INTO `schema_migrations` VALUES").twice - expect(renderer.render).to include("20221219191938").once - expect(renderer.render).to include("20221219195431").once - expect(renderer.render).to include("20221219231318").once - expect(renderer.render).to include("20221219231320").once - expect(renderer.render).to include("20221219231322").once - expect(renderer.render).to include("20221219231323").once - expect(renderer.render).to include("20221219231324").once + expect(subject).to include("INSERT INTO `schema_migrations` VALUES").twice + expect(subject).to include("20221219191938").once + expect(subject).to include("20221219195431").once + expect(subject).to include("20221221142539").once end end From 2208a9749b63bcff17dc341e6ff4386bd7467fef Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:38:46 -0300 Subject: [PATCH 16/32] Lower migrations to oldest supported rails --- .../db/migrate/20221219203032_create_marketing_leads.rb | 2 +- .../db/migrate/20221219195431_create_payroll_salaries.rb | 2 +- .../sales/db/migrate/20221219191938_create_sales_prices.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb b/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb index 72070259..74cff307 100644 --- a/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb +++ b/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateMarketingLeads < ActiveRecord::Migration[7.0] +class CreateMarketingLeads < ActiveRecord::Migration[5.2] def change create_table :marketing_leads do |t| t.string :name diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb index 1a89ec44..7ebd58da 100644 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreatePayrollSalaries < ActiveRecord::Migration[7.0] +class CreatePayrollSalaries < ActiveRecord::Migration[5.2] def change create_table :payroll_salaries do |t| t.integer :value diff --git a/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb b/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb index 90f41230..b3b7baa9 100644 --- a/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb +++ b/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSalesPrices < ActiveRecord::Migration[7.0] +class CreateSalesPrices < ActiveRecord::Migration[5.2] def change create_table :sales_prices do |t| t.integer :value From 44027ace35c10b326875f2e9148cd2193121dc97 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 11:42:07 -0300 Subject: [PATCH 17/32] Load defaults for oldest supported rails --- packages/edgestitch/spec/dummy/config/application.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/edgestitch/spec/dummy/config/application.rb b/packages/edgestitch/spec/dummy/config/application.rb index de30b322..855b666c 100644 --- a/packages/edgestitch/spec/dummy/config/application.rb +++ b/packages/edgestitch/spec/dummy/config/application.rb @@ -14,8 +14,7 @@ module Dummy class Application < Rails::Application - # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.0 + config.load_defaults 5.2 config.active_record.schema_format = :sql end From e57e6a9c298d8e19fc98e953c5f9cefca6cc1a8f Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 12:44:35 -0300 Subject: [PATCH 18/32] Drop support for rails 5.2 on edgestitch --- .github/workflows/edgestitch.yml | 1 + packages/edgestitch/spec/dummy/config/application.rb | 2 +- .../db/migrate/20221219203032_create_marketing_leads.rb | 2 +- .../db/migrate/20221219195431_create_payroll_salaries.rb | 2 +- .../payroll/db/migrate/20221221142539_create_payroll_ghosts.rb | 2 +- .../sales/db/migrate/20221219191938_create_sales_prices.rb | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/edgestitch.yml b/.github/workflows/edgestitch.yml index b12edc74..101a83c5 100644 --- a/.github/workflows/edgestitch.yml +++ b/.github/workflows/edgestitch.yml @@ -10,4 +10,5 @@ jobs: package: ${{ github.workflow }} workdir: 'packages/${{ github.workflow }}' before_build: sudo /etc/init.d/mysql start + rails: "['6.0','6.1','7.0']" secrets: inherit diff --git a/packages/edgestitch/spec/dummy/config/application.rb b/packages/edgestitch/spec/dummy/config/application.rb index 855b666c..856c9dfc 100644 --- a/packages/edgestitch/spec/dummy/config/application.rb +++ b/packages/edgestitch/spec/dummy/config/application.rb @@ -14,7 +14,7 @@ module Dummy class Application < Rails::Application - config.load_defaults 5.2 + config.load_defaults 6.0 config.active_record.schema_format = :sql end diff --git a/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb b/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb index 74cff307..44fd4d0c 100644 --- a/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb +++ b/packages/edgestitch/spec/dummy/engines/marketing/db/migrate/20221219203032_create_marketing_leads.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateMarketingLeads < ActiveRecord::Migration[5.2] +class CreateMarketingLeads < ActiveRecord::Migration[6.0] def change create_table :marketing_leads do |t| t.string :name diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb index 7ebd58da..7b3343c4 100644 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221219195431_create_payroll_salaries.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreatePayrollSalaries < ActiveRecord::Migration[5.2] +class CreatePayrollSalaries < ActiveRecord::Migration[6.0] def change create_table :payroll_salaries do |t| t.integer :value diff --git a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb index 15e177cd..310c8541 100644 --- a/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb +++ b/packages/edgestitch/spec/dummy/engines/payroll/db/migrate/20221221142539_create_payroll_ghosts.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreatePayrollGhosts < ActiveRecord::Migration[5.2] +class CreatePayrollGhosts < ActiveRecord::Migration[6.0] def change create_table :payroll_ghosts do |t| t.string :name diff --git a/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb b/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb index b3b7baa9..86d6fae5 100644 --- a/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb +++ b/packages/edgestitch/spec/dummy/engines/sales/db/migrate/20221219191938_create_sales_prices.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class CreateSalesPrices < ActiveRecord::Migration[5.2] +class CreateSalesPrices < ActiveRecord::Migration[6.0] def change create_table :sales_prices do |t| t.integer :value From d6aeeed91803b7084608f8d7490f893bc3ca583f Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 12:45:16 -0300 Subject: [PATCH 19/32] Rename patchwork spec dir to edgestitch --- .../edgestitch/spec/{patchwork => edgestitch}/exporter_spec.rb | 0 .../edgestitch/spec/{patchwork => edgestitch}/renderer_spec.rb | 0 packages/edgestitch/spec/{patchwork => edgestitch}/tasks_spec.rb | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename packages/edgestitch/spec/{patchwork => edgestitch}/exporter_spec.rb (100%) rename packages/edgestitch/spec/{patchwork => edgestitch}/renderer_spec.rb (100%) rename packages/edgestitch/spec/{patchwork => edgestitch}/tasks_spec.rb (100%) diff --git a/packages/edgestitch/spec/patchwork/exporter_spec.rb b/packages/edgestitch/spec/edgestitch/exporter_spec.rb similarity index 100% rename from packages/edgestitch/spec/patchwork/exporter_spec.rb rename to packages/edgestitch/spec/edgestitch/exporter_spec.rb diff --git a/packages/edgestitch/spec/patchwork/renderer_spec.rb b/packages/edgestitch/spec/edgestitch/renderer_spec.rb similarity index 100% rename from packages/edgestitch/spec/patchwork/renderer_spec.rb rename to packages/edgestitch/spec/edgestitch/renderer_spec.rb diff --git a/packages/edgestitch/spec/patchwork/tasks_spec.rb b/packages/edgestitch/spec/edgestitch/tasks_spec.rb similarity index 100% rename from packages/edgestitch/spec/patchwork/tasks_spec.rb rename to packages/edgestitch/spec/edgestitch/tasks_spec.rb From 0dbe367f6a5dded5a1c685f235ef352d7fea0bca Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Wed, 21 Dec 2022 20:01:37 -0300 Subject: [PATCH 20/32] Avoid empty file while writting new structure-self.sql --- packages/edgestitch/lib/edgestitch/exporter.rb | 9 +++++++-- packages/edgestitch/spec/edgestitch/exporter_spec.rb | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/edgestitch/lib/edgestitch/exporter.rb b/packages/edgestitch/lib/edgestitch/exporter.rb index bc8d80cf..ed91f41a 100644 --- a/packages/edgestitch/lib/edgestitch/exporter.rb +++ b/packages/edgestitch/lib/edgestitch/exporter.rb @@ -17,8 +17,13 @@ def initialize(engine) @structure_file_path = @database_directory_path.join("structure-self.sql") end - def export(dump, io: @structure_file_path.open("w")) - io.puts [dump.export_tables(tables), dump.export_migrations(migrations)].join("\n\n").strip + def export(dump, to: @structure_file_path) + StringIO.open do |buffer| + buffer.puts dump.export_tables(tables) + buffer.puts + buffer.puts dump.export_migrations(migrations) + File.write to, "#{buffer.string.strip}\n" + end end def migrations diff --git a/packages/edgestitch/spec/edgestitch/exporter_spec.rb b/packages/edgestitch/spec/edgestitch/exporter_spec.rb index 3d3455ac..c77b3221 100644 --- a/packages/edgestitch/spec/edgestitch/exporter_spec.rb +++ b/packages/edgestitch/spec/edgestitch/exporter_spec.rb @@ -7,11 +7,11 @@ it "exports the tables of models owned by the engine" do exporter = Edgestitch::Exporter.new(Sales::Engine) - output = StringIO.new + tempfile = Tempfile.new - exporter.export(dump, io: output) + exporter.export(dump, to: tempfile.path) - expect(output.string).to eql "tables sql\n\nmigrations sql\n" + expect(tempfile.read).to eql "tables sql\n\nmigrations sql\n" end it "selects the tables belonging to the given engine" do From 8fb38d43ed0eabc6ece893675d78ff53b2a965d6 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 13:45:17 -0300 Subject: [PATCH 21/32] Add YARD documentation --- packages/edgestitch/lib/edgestitch.rb | 18 ++++++-- .../edgestitch/lib/edgestitch/exporter.rb | 10 ++++- .../edgestitch/lib/edgestitch/mysql/dump.rb | 26 +++++++++++- .../structure_constraint_order_munger.rb | 1 + packages/edgestitch/lib/edgestitch/railtie.rb | 3 ++ .../edgestitch/lib/edgestitch/renderer.rb | 4 +- packages/edgestitch/lib/edgestitch/tasks.rb | 41 ++++++++++++++++++- 7 files changed, 95 insertions(+), 8 deletions(-) diff --git a/packages/edgestitch/lib/edgestitch.rb b/packages/edgestitch/lib/edgestitch.rb index 3d45269e..813fff03 100644 --- a/packages/edgestitch/lib/edgestitch.rb +++ b/packages/edgestitch/lib/edgestitch.rb @@ -7,8 +7,20 @@ require "edgestitch/mysql/dump" -# TODO: doc -# @private +# Facade module to access public Edgestitch functions +# module Edgestitch - def self.install_self; end + module_function + + # Define a db:stitch task + # @see Edgestitch::Tasks + def define_create(...) + ::Edgestitch::Tasks.define_create(...) + end + + # Define a db:stitch: task + # @see Edgestitch::Tasks + def define_self(...) + ::Edgestitch::Tasks.define_self(...) + end end diff --git a/packages/edgestitch/lib/edgestitch/exporter.rb b/packages/edgestitch/lib/edgestitch/exporter.rb index ed91f41a..6e98b700 100644 --- a/packages/edgestitch/lib/edgestitch/exporter.rb +++ b/packages/edgestitch/lib/edgestitch/exporter.rb @@ -1,9 +1,17 @@ # frozen_string_literal: true module Edgestitch - # TODO: doc # @private + # + # This class is responsible for exporting an engine's owned tables and + # migrations to a SQL file. + # class Exporter + # Exports an engine using a dump helper (@see Edgestitch::Mysql::Dump) + # + # @param engine [Class] the engine to export + # @param dump [<#export_tables,#export_migrations>] the dump helper + # def self.export(engine, dump) new(engine).export(dump) end diff --git a/packages/edgestitch/lib/edgestitch/mysql/dump.rb b/packages/edgestitch/lib/edgestitch/mysql/dump.rb index 2cebca66..a71d5360 100644 --- a/packages/edgestitch/lib/edgestitch/mysql/dump.rb +++ b/packages/edgestitch/lib/edgestitch/mysql/dump.rb @@ -6,9 +6,18 @@ module Edgestitch module Mysql - # TODO: doc # @private + # + # Wrapper for the mysqldump tool to dump specific tables and migration data + # class Dump + # Sanitizes a DDL code with some opinionated preferences: + # * Constraints starting with `_fk` will start with `fk` + # * Clear empty lines (with empty spaces even) + # * Reorder constraints (@see Edgestitch::Mysql::StructureConstraintOrderMunger) + # + # @param sql [String] the DDL code to sanitize + # @return String the same DDL sanitized def self.sanitize_sql(sql) comment_instructions_regex = %r{^/\*![0-9]{5}\s+[^;]+;\s*$} @@ -20,6 +29,8 @@ def self.sanitize_sql(sql) ::Edgestitch::Mysql::StructureConstraintOrderMunger.munge(cleanups) end + # + # @param config [ActiveRecord::DatabaseConfigurations::DatabaseConfig] rails database configuration def initialize(config) hash = config.respond_to?(:configuration_hash) ? config.configuration_hash : config.config @database = hash["database"] || hash[:database] @@ -31,6 +42,10 @@ def initialize(config) } end + # Exports DDL for the given tables in a mysql compatible way + # + # @param tables [Array] table names + # @return String the DDL for the given tables def export_tables(tables) return if tables.empty? @@ -40,6 +55,15 @@ def export_tables(tables) ) end + + # Exports INSERT statements for the given migration names. + # + # The INSERT statements are in groups of 50 migrations per multi-insert statement. + # + # Notice: this does not export the creation of the schema_migrations table. + # + # @param migrations [Array] migration ids/timestamps + # @return String the INSERT statements. def export_migrations(migrations) migrations.in_groups_of(50, false).map do |versions| execute( diff --git a/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb b/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb index 8f027297..c998d389 100644 --- a/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb +++ b/packages/edgestitch/lib/edgestitch/mysql/structure_constraint_order_munger.rb @@ -2,6 +2,7 @@ module Edgestitch module Mysql + # @private class StructureConstraintOrderMunger class << self def munge(sql) diff --git a/packages/edgestitch/lib/edgestitch/railtie.rb b/packages/edgestitch/lib/edgestitch/railtie.rb index d5e4a6d0..abf6da21 100644 --- a/packages/edgestitch/lib/edgestitch/railtie.rb +++ b/packages/edgestitch/lib/edgestitch/railtie.rb @@ -3,6 +3,9 @@ require "edgestitch" module Edgestitch + # Railtie to install the stitch task (db:stitch). + # require this railtie to automatically install the stitch task for the app, + # or define it manually adding `::Edgestitch.define_create` to your Rakefile. class Railtie < ::Rails::Railtie rake_tasks { ::Edgestitch::Tasks.define_create } end diff --git a/packages/edgestitch/lib/edgestitch/renderer.rb b/packages/edgestitch/lib/edgestitch/renderer.rb index 60a43fa0..146cfe74 100644 --- a/packages/edgestitch/lib/edgestitch/renderer.rb +++ b/packages/edgestitch/lib/edgestitch/renderer.rb @@ -3,8 +3,10 @@ require "erb" module Edgestitch - # TODO: doc # @private + # + # Renders a structure.sql file based on all given engine's structure-self.sql + # class Renderer def initialize(engines) @engines = Set.new(engines) diff --git a/packages/edgestitch/lib/edgestitch/tasks.rb b/packages/edgestitch/lib/edgestitch/tasks.rb index d80a555a..0713bef1 100644 --- a/packages/edgestitch/lib/edgestitch/tasks.rb +++ b/packages/edgestitch/lib/edgestitch/tasks.rb @@ -3,12 +3,35 @@ require "rake/tasklib" module Edgestitch - # TODO: doc # @private + # + # Define rake tasks to deal with edgestitch structurefiles: + # + # db:stitch: creates a structure.sql out of loaded engines and application + # structure-self.sql + # db:stitch:: creates a structure-self.sql containing only the + # engine's models and migrations + # + # In order to integrate well with rails, it also enhances tasks like db:structure:load, + # db:prepare and others. + # module Tasks class << self include Rake::DSL + # Defines a task to stitch a structure.sql from loaded Engines. + # This task is responsible for gathering all loaded engines and the current + # application's structrure-self.sql and stitching them together into a + # structure.sql. + # + # Rails enhancements will happen before each of these tasks: + # + # - db:prepare + # - db:structure:load + # - db:schema:load + # + # @param namespace [String] namespace where the task will run [default: db:stitch] + # @return [Rake::Task] def define_create(namespace = "db:stitch") enhance(namespace, "db:prepare", "db:structure:load", "db:schema:load") desc "Create structure.sql for an app based on all loaded engines' structure-self.sql" @@ -19,6 +42,21 @@ def define_create(namespace = "db:stitch") end end + # Defines a task to generate the structure-self.sql file from an engine. + # This task is responsible for gathering all models owned by the engine and all + # migrations defined within the engine and generate a structure-self.sql. + # + # Rails enhancements will happen before each of these tasks: + # + # - db:structure:dump + # - db:schema:dump + # - app:db:structure:dump + # - app:db:schema:dump + # + # @param engine [Class] target class of the task + # @param namespace [String] the namespace where the target will be generated [default: db:stitch] + # @param name [String] the name of the task within the given namespace [default: engine.engine_name] + # @return [Rake::Task] def define_self(engine, namespace: "db:stitch", name: engine.engine_name) enhance("#{namespace}:#{name}", "db:structure:dump", "app:db:structure:dump", "db:schema:dump", "app:db:schema:dump") @@ -27,7 +65,6 @@ def define_self(engine, namespace: "db:stitch", name: engine.engine_name) task "#{namespace}:#{name}" => [:environment] do |_, _args| Rails.application.eager_load! engine&.eager_load! - # puts *caller ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| ::Edgestitch::Exporter.export(engine, ::Edgestitch::Mysql::Dump.new(db_config)) end From b42b83dcbb963ce107e06a6f7740dc0fb80ad28b Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 14:00:59 -0300 Subject: [PATCH 22/32] Rename renderer to stitcher --- packages/edgestitch/lib/edgestitch.rb | 2 +- packages/edgestitch/lib/edgestitch/mysql/dump.rb | 1 - .../lib/edgestitch/{renderer.rb => stitcher.rb} | 6 +++--- packages/edgestitch/lib/edgestitch/tasks.rb | 2 +- .../edgestitch/{renderer_spec.rb => stitcher_spec.rb} | 10 +++------- packages/edgestitch/spec/edgestitch/tasks_spec.rb | 10 +++++----- 6 files changed, 13 insertions(+), 18 deletions(-) rename packages/edgestitch/lib/edgestitch/{renderer.rb => stitcher.rb} (83%) rename packages/edgestitch/spec/edgestitch/{renderer_spec.rb => stitcher_spec.rb} (85%) diff --git a/packages/edgestitch/lib/edgestitch.rb b/packages/edgestitch/lib/edgestitch.rb index 813fff03..015e4e7f 100644 --- a/packages/edgestitch/lib/edgestitch.rb +++ b/packages/edgestitch/lib/edgestitch.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "edgestitch/exporter" -require "edgestitch/renderer" +require "edgestitch/stitcher" require "edgestitch/tasks" require "edgestitch/version" diff --git a/packages/edgestitch/lib/edgestitch/mysql/dump.rb b/packages/edgestitch/lib/edgestitch/mysql/dump.rb index a71d5360..ea64d244 100644 --- a/packages/edgestitch/lib/edgestitch/mysql/dump.rb +++ b/packages/edgestitch/lib/edgestitch/mysql/dump.rb @@ -55,7 +55,6 @@ def export_tables(tables) ) end - # Exports INSERT statements for the given migration names. # # The INSERT statements are in groups of 50 migrations per multi-insert statement. diff --git a/packages/edgestitch/lib/edgestitch/renderer.rb b/packages/edgestitch/lib/edgestitch/stitcher.rb similarity index 83% rename from packages/edgestitch/lib/edgestitch/renderer.rb rename to packages/edgestitch/lib/edgestitch/stitcher.rb index 146cfe74..481ca565 100644 --- a/packages/edgestitch/lib/edgestitch/renderer.rb +++ b/packages/edgestitch/lib/edgestitch/stitcher.rb @@ -7,7 +7,7 @@ module Edgestitch # # Renders a structure.sql file based on all given engine's structure-self.sql # - class Renderer + class Stitcher def initialize(engines) @engines = Set.new(engines) end @@ -18,11 +18,11 @@ def each_file(&block) .uniq.each(&block) end - def self.to_file(engines, file) + def self.to_file(file, *engines) File.write(file, new(engines).render) end end end erb = ERB.new(File.read(File.join(__dir__, "stitch.sql.erb"))) -erb.def_method(Edgestitch::Renderer, "render()") +erb.def_method(Edgestitch::Stitcher, "render()") diff --git a/packages/edgestitch/lib/edgestitch/tasks.rb b/packages/edgestitch/lib/edgestitch/tasks.rb index 0713bef1..29e1fd98 100644 --- a/packages/edgestitch/lib/edgestitch/tasks.rb +++ b/packages/edgestitch/lib/edgestitch/tasks.rb @@ -37,7 +37,7 @@ def define_create(namespace = "db:stitch") desc "Create structure.sql for an app based on all loaded engines' structure-self.sql" task namespace => [:environment] do |_task, _args| ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| - ::Edgestitch::Renderer.to_file([*::Rails::Engine.subclasses, Rails.application], filename(db_config)) + ::Edgestitch::Stitcher.to_file(filename(db_config), *::Rails::Engine.subclasses, Rails.application) end end end diff --git a/packages/edgestitch/spec/edgestitch/renderer_spec.rb b/packages/edgestitch/spec/edgestitch/stitcher_spec.rb similarity index 85% rename from packages/edgestitch/spec/edgestitch/renderer_spec.rb rename to packages/edgestitch/spec/edgestitch/stitcher_spec.rb index 6fe04c11..e2ef6102 100644 --- a/packages/edgestitch/spec/edgestitch/renderer_spec.rb +++ b/packages/edgestitch/spec/edgestitch/stitcher_spec.rb @@ -2,13 +2,9 @@ require "rails_helper" -RSpec.describe Edgestitch::Renderer do - before do - Rails.application.eager_load! - end - - let(:renderer) { Edgestitch::Renderer.new([Sales::Engine, Payroll::Engine]) } - subject { renderer.render } +RSpec.describe Edgestitch::Stitcher do + let(:stitcher) { Edgestitch::Stitcher.new([Sales::Engine, Payroll::Engine]) } + subject { stitcher.render } it "renders tables from all given components" do expect(subject).to include("spec/dummy/engines/sales/db/structure-self.sql").once diff --git a/packages/edgestitch/spec/edgestitch/tasks_spec.rb b/packages/edgestitch/spec/edgestitch/tasks_spec.rb index 042ccbb2..603c2d63 100644 --- a/packages/edgestitch/spec/edgestitch/tasks_spec.rb +++ b/packages/edgestitch/spec/edgestitch/tasks_spec.rb @@ -31,11 +31,11 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize end it "renders the structure.sql with all loaded engines" do - expect(Edgestitch::Renderer).to( - receive(:to_file).with( - array_including([Marketing::Engine, Payroll::Engine, Sales::Engine]), - Rails.root.join("db", "structure.sql").to_s - ) + expect(Edgestitch::Stitcher).to( + receive(:to_file) do |file, *engines| + expect(file).to eq Rails.root.join("db", "structure.sql").to_s + expect(engines).to include(Marketing::Engine, Payroll::Engine, Sales::Engine, Rails.application) + end ) rake_execute "db:stitch" From 5a415d1d28c9e56f7b83d98d7291bcdec84e46ed Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 14:01:52 -0300 Subject: [PATCH 23/32] Rename task definition methods --- packages/edgestitch/lib/edgestitch.rb | 10 +++++----- packages/edgestitch/lib/edgestitch/railtie.rb | 4 ++-- packages/edgestitch/lib/edgestitch/tasks.rb | 4 ++-- packages/edgestitch/spec/dummy/Rakefile | 6 +++--- packages/edgestitch/spec/edgestitch/tasks_spec.rb | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/edgestitch/lib/edgestitch.rb b/packages/edgestitch/lib/edgestitch.rb index 015e4e7f..ecfdac79 100644 --- a/packages/edgestitch/lib/edgestitch.rb +++ b/packages/edgestitch/lib/edgestitch.rb @@ -10,17 +10,17 @@ # Facade module to access public Edgestitch functions # module Edgestitch - module_function +module_function # Define a db:stitch task # @see Edgestitch::Tasks - def define_create(...) - ::Edgestitch::Tasks.define_create(...) + def define_stitch(...) + ::Edgestitch::Tasks.define_stitch(...) end # Define a db:stitch: task # @see Edgestitch::Tasks - def define_self(...) - ::Edgestitch::Tasks.define_self(...) + def define_engine(...) + ::Edgestitch::Tasks.define_engine(...) end end diff --git a/packages/edgestitch/lib/edgestitch/railtie.rb b/packages/edgestitch/lib/edgestitch/railtie.rb index abf6da21..7d5e6cc6 100644 --- a/packages/edgestitch/lib/edgestitch/railtie.rb +++ b/packages/edgestitch/lib/edgestitch/railtie.rb @@ -5,8 +5,8 @@ module Edgestitch # Railtie to install the stitch task (db:stitch). # require this railtie to automatically install the stitch task for the app, - # or define it manually adding `::Edgestitch.define_create` to your Rakefile. + # or define it manually adding `::Edgestitch.define_stitch` to your Rakefile. class Railtie < ::Rails::Railtie - rake_tasks { ::Edgestitch::Tasks.define_create } + rake_tasks { ::Edgestitch::Tasks.define_stitch } end end diff --git a/packages/edgestitch/lib/edgestitch/tasks.rb b/packages/edgestitch/lib/edgestitch/tasks.rb index 29e1fd98..3993385d 100644 --- a/packages/edgestitch/lib/edgestitch/tasks.rb +++ b/packages/edgestitch/lib/edgestitch/tasks.rb @@ -32,7 +32,7 @@ class << self # # @param namespace [String] namespace where the task will run [default: db:stitch] # @return [Rake::Task] - def define_create(namespace = "db:stitch") + def define_stitch(namespace = "db:stitch") enhance(namespace, "db:prepare", "db:structure:load", "db:schema:load") desc "Create structure.sql for an app based on all loaded engines' structure-self.sql" task namespace => [:environment] do |_task, _args| @@ -57,7 +57,7 @@ def define_create(namespace = "db:stitch") # @param namespace [String] the namespace where the target will be generated [default: db:stitch] # @param name [String] the name of the task within the given namespace [default: engine.engine_name] # @return [Rake::Task] - def define_self(engine, namespace: "db:stitch", name: engine.engine_name) + def define_engine(engine, namespace: "db:stitch", name: engine.engine_name) enhance("#{namespace}:#{name}", "db:structure:dump", "app:db:structure:dump", "db:schema:dump", "app:db:schema:dump") diff --git a/packages/edgestitch/spec/dummy/Rakefile b/packages/edgestitch/spec/dummy/Rakefile index 38012519..a50fbe40 100644 --- a/packages/edgestitch/spec/dummy/Rakefile +++ b/packages/edgestitch/spec/dummy/Rakefile @@ -7,6 +7,6 @@ require_relative "config/application" Rails.application.load_tasks -Edgestitch::Tasks.define_self(Marketing::Engine) -Edgestitch::Tasks.define_self(Payroll::Engine) -Edgestitch::Tasks.define_self(Sales::Engine) +Edgestitch::Tasks.define_engine(Marketing::Engine) +Edgestitch::Tasks.define_engine(Payroll::Engine) +Edgestitch::Tasks.define_engine(Sales::Engine) diff --git a/packages/edgestitch/spec/edgestitch/tasks_spec.rb b/packages/edgestitch/spec/edgestitch/tasks_spec.rb index 603c2d63..76f42c78 100644 --- a/packages/edgestitch/spec/edgestitch/tasks_spec.rb +++ b/packages/edgestitch/spec/edgestitch/tasks_spec.rb @@ -63,7 +63,7 @@ def dry_run(task, ...) # rubocop:disable Metrics/AbcSize end describe ":self" do - before(:all) { Edgestitch::Tasks.define_self(Sales::Engine, namespace: "db:spec") } + before(:all) { Edgestitch::Tasks.define_engine(Sales::Engine, namespace: "db:spec") } before { Rake::Task["db:spec:sales"].reenable } it "defines the create task to create a structure-self.sql" do From 97406499043fdf9852b57b1483fdc98b349a0963 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 14:18:31 -0300 Subject: [PATCH 24/32] Update edgestitch.gemspec with the correct info --- packages/edgestitch/edgestitch.gemspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/edgestitch/edgestitch.gemspec b/packages/edgestitch/edgestitch.gemspec index a891adcb..a14daf54 100644 --- a/packages/edgestitch/edgestitch.gemspec +++ b/packages/edgestitch/edgestitch.gemspec @@ -10,8 +10,7 @@ Gem::Specification.new do |spec| spec.authors = ["Carlos Palhares"] spec.email = ["chjunior@gmail.com"] - spec.summary = "Power-ful logging wrapper" - spec.description = "Lumberaxe handles logging output formatting." + spec.description = spec.summary = "Edgestitch allows engines to define partial structure-self.sql files to be stitched into a single structure.sql file by the umbrella application" spec.homepage = "https://github.com/powerhome/power-tools" spec.license = "MIT" spec.required_ruby_version = ">= 2.7" @@ -19,7 +18,7 @@ Gem::Specification.new do |spec| spec.metadata["rubygems_mfa_required"] = "true" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage - spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/lumberaxe/docs/CHANGELOG.md" + spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/packages/edgestitch/docs/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. From 567f3a757da0690bb0710426ba36c1454b6345c3 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 14:41:48 -0300 Subject: [PATCH 25/32] Add README info --- docs/README.md | 4 ++ packages/edgestitch/docs/CHANGELOG.md | 4 ++ packages/edgestitch/docs/README.md | 99 +++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 packages/edgestitch/docs/CHANGELOG.md create mode 100644 packages/edgestitch/docs/README.md diff --git a/docs/README.md b/docs/README.md index 65ffb2aa..5f8278ba 100644 --- a/docs/README.md +++ b/docs/README.md @@ -42,6 +42,10 @@ Helping ruby developers implement easy patterns. A shared layout so that your suite of applications can have the same look and feel. +[edgestitch](https://github.com/powerhome/power-tools/blob/main/packages/edgestitch/docs/README.md) 💎 + +Edgestitch allows engines to define partial structure-self.sql files to be stitched into a single structure.sql file by the umbrella application. + ## Installation 🛠 These packages are all meant to install inside of an application and aren't intended to stand alone; currently, they are all published to [RubyGems](https://rubygems.org/) and you can use standard Bundler methods to install them. diff --git a/packages/edgestitch/docs/CHANGELOG.md b/packages/edgestitch/docs/CHANGELOG.md new file mode 100644 index 00000000..4d6f7808 --- /dev/null +++ b/packages/edgestitch/docs/CHANGELOG.md @@ -0,0 +1,4 @@ +## [1.0.0] - 2022-12-22 + +- First release of Edgestitch, extracted from NitroMysql. +- Supports all rails >= 6.0 and all ruby >= 2.7 \ No newline at end of file diff --git a/packages/edgestitch/docs/README.md b/packages/edgestitch/docs/README.md new file mode 100644 index 00000000..123e1546 --- /dev/null +++ b/packages/edgestitch/docs/README.md @@ -0,0 +1,99 @@ +# Edgestitch + +Edgestitch allows engines to define partial structure-self.sql files to be stitched into a single structure.sql file by the umbrella application. This allows big teams to develop large [Cobra](https://cbra.info) [Applications](https://github.com/powerhome/cobra_commander) without much conflict happening in a single structure.sql file. Instead, each team will more likely update one component or two structure-self.sql files while other teams concerned with other areas of the application will be changing different files. + +## Installation + +### Umbrella App + +Add this line to your application's Gemfile: + +```ruby +# Gemfile + +gem "edgestitch", require: false +``` + +And then execute: + + $ bundle install + +Then require the railtie in the umbrella's `config/application.rb`: + +```ruby +# config/application.rb + +require "edgestitch/railtie" +``` + +If your umbrella app also has migrations or even models, you'll have to also install the engine task to your `Rakefile`: + +```ruby +# Rakefile + +Edgestitch.define_engine(::My::Application) +``` + +### Engines + +Each internal engine will also have a development dependency on `edgestitch`, and can install it the same way: + +```ruby +# crazy.gemspec + +spec.add_development_dependency "edgestitch" +``` + +And then execute: + + $ bundle install + +And install the helper tasks: + +```ruby +Edgestitch.define_engine(::Crazy::Engine) +``` + +You'll also have to add the `railtie` to the dummy app (as they're dummy umbrella apps), in case the engine has external database dependencies. + +```ruby +# spec/dummy/config/application.rb + +require "edgestitch/railtie" +``` + +## Usage + +Edgestitch will enhance the default rails tasks, so using nothing special has to be done in order to use it. Once edgestitch is correctly installed things should Just Work™️ as explained in the rails manual, but it will be generating `structure-self.sql` along with `structure.sql` files. **Important**: It's recommended that `structure.sql` files are added to `.gitignore`. + +# How does it work + +Edgestitch works based on table and migrations ownership. Based on these ownerships, Edgestitch can export a `structure-self.sql` file defining the DDL owned by a specific engine. + +The stitching process then takes all loaded engines (assuming the dependency between engines is defined correctly) and assembles a structure.sql file. + +## Table and Migration Ownerships + +A model is owned by an engine when it inherits from the Engine's ApplicationModel, and thus the table is owned by that engine. A migration is owned by the engine if it is defined within its `db/migrate` directory. + +## Extra tables + +Sometimes an external dependency brings in extra tables that are not defined in any `structure-self.sql`. To be part of the ecosystem, the new tables should be owned by the engine adding them. That can be done by adding these tables to `/db/extra_tables`. It's a simple text file with a list of table names that do not inherit from `::AplicationModel`, but are owned by that engine and should be included in its structure-self.sql. + +## External Gems + +An external gem can also define a `structure-self.sql` file to be adapted in this ecosystem. That can be done using the same approach specified in Installation / Engines. + +## Development + +After 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. + +To 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/powerhome/power-tools. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). From 1db129f6d677af04700777db3d87bf6e1af72149 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 14:47:10 -0300 Subject: [PATCH 26/32] Add portal documentation --- packages/consent/mkdocs.yml | 1 + packages/edgestitch/mkdocs.yml | 6 ++++++ portal.yml | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 packages/edgestitch/mkdocs.yml diff --git a/packages/consent/mkdocs.yml b/packages/consent/mkdocs.yml index 51c97156..3b2f7f02 100644 --- a/packages/consent/mkdocs.yml +++ b/packages/consent/mkdocs.yml @@ -1,5 +1,6 @@ site_name: Consent nav: - "Home": "README.md" + - "Changelog": "CHANGELOG.md" plugins: - techdocs-core diff --git a/packages/edgestitch/mkdocs.yml b/packages/edgestitch/mkdocs.yml new file mode 100644 index 00000000..b895b1d0 --- /dev/null +++ b/packages/edgestitch/mkdocs.yml @@ -0,0 +1,6 @@ +site_name: Edgestitch +nav: + - "Home": "README.md" + - "Changelog": "CHANGELOG.md" +plugins: + - techdocs-core diff --git a/portal.yml b/portal.yml index 474f5a2f..2c724597 100644 --- a/portal.yml +++ b/portal.yml @@ -140,3 +140,19 @@ spec: system: power-application-framework lifecycle: production subcomponentOf: power-tools +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: edgestitch + title: Edgestitch + description: >- + Edgestitch allows engines to define partial structure-self.sql + files to be stitched into a single structure.sql file by the + umbrella application +spec: + type: library + owner: heroes-for-hire + system: power-application-framework + lifecycle: production + subcomponentOf: power-tools From 8244d1391feae60d37943e9826190bbb4f0a8a94 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 14:49:58 -0300 Subject: [PATCH 27/32] Fix rubocop violation --- packages/edgestitch/edgestitch.gemspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/edgestitch/edgestitch.gemspec b/packages/edgestitch/edgestitch.gemspec index a14daf54..1cb71ce9 100644 --- a/packages/edgestitch/edgestitch.gemspec +++ b/packages/edgestitch/edgestitch.gemspec @@ -10,7 +10,8 @@ Gem::Specification.new do |spec| spec.authors = ["Carlos Palhares"] spec.email = ["chjunior@gmail.com"] - spec.description = spec.summary = "Edgestitch allows engines to define partial structure-self.sql files to be stitched into a single structure.sql file by the umbrella application" + spec.description = spec.summary = "Edgestitch allows engines to define partial structure-self.sql files to be " \ + "stitched into a single structure.sql file by the umbrella application" spec.homepage = "https://github.com/powerhome/power-tools" spec.license = "MIT" spec.required_ruby_version = ">= 2.7" From ac135eeabdf6b4c0a0cd7cdfb56dfd9230345c3b Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 16:15:48 -0300 Subject: [PATCH 28/32] Drop 5.2 for good --- packages/edgestitch/Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/edgestitch/Gemfile b/packages/edgestitch/Gemfile index b85a9cbb..41d746ad 100644 --- a/packages/edgestitch/Gemfile +++ b/packages/edgestitch/Gemfile @@ -4,6 +4,6 @@ source "https://rubygems.org" gemspec -rails_version = ENV.fetch("RAILS_VERSION", ">= 5.2.8.1") +rails_version = ENV.fetch("RAILS_VERSION", ">= 6.0.6") gem "rails", rails_version From 51c01865f3a32530134ff4811e3c51baa69d948c Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 18:49:06 -0300 Subject: [PATCH 29/32] Remove unnecessary rails generated files --- .../application_controller_renderer.rb | 9 ----- .../spec/dummy/config/initializers/assets.rb | 13 -------- .../initializers/backtrace_silencers.rb | 8 ----- .../initializers/content_security_policy.rb | 29 ---------------- .../dummy/config/initializers/inflections.rb | 17 ---------- .../dummy/config/initializers/mime_types.rb | 5 --- .../spec/dummy/config/locales/en.yml | 33 ------------------- 7 files changed, 114 deletions(-) delete mode 100644 packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb delete mode 100644 packages/edgestitch/spec/dummy/config/initializers/assets.rb delete mode 100644 packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb delete mode 100644 packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb delete mode 100644 packages/edgestitch/spec/dummy/config/initializers/inflections.rb delete mode 100644 packages/edgestitch/spec/dummy/config/initializers/mime_types.rb delete mode 100644 packages/edgestitch/spec/dummy/config/locales/en.yml diff --git a/packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb b/packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb deleted file mode 100644 index f4556db3..00000000 --- a/packages/edgestitch/spec/dummy/config/initializers/application_controller_renderer.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true -# Be sure to restart your server when you modify this file. - -# ActiveSupport::Reloader.to_prepare do -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) -# end diff --git a/packages/edgestitch/spec/dummy/config/initializers/assets.rb b/packages/edgestitch/spec/dummy/config/initializers/assets.rb deleted file mode 100644 index 6f260d5c..00000000 --- a/packages/edgestitch/spec/dummy/config/initializers/assets.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true -# Be sure to restart your server when you modify this file. - -# Version of your assets, change this if you want to expire all your assets. -# Rails.application.config.assets.version = '1.0' - -# Add additional assets to the asset load path. -# Rails.application.config.assets.paths << Emoji.images_path - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb b/packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb deleted file mode 100644 index d0f0d3b5..00000000 --- a/packages/edgestitch/spec/dummy/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! diff --git a/packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb b/packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb deleted file mode 100644 index 98230c98..00000000 --- a/packages/edgestitch/spec/dummy/config/initializers/content_security_policy.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true -# Be sure to restart your server when you modify this file. - -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy - -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https - -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" -# end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/packages/edgestitch/spec/dummy/config/initializers/inflections.rb b/packages/edgestitch/spec/dummy/config/initializers/inflections.rb deleted file mode 100644 index aa7435fb..00000000 --- a/packages/edgestitch/spec/dummy/config/initializers/inflections.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true -# Be sure to restart your server when you modify this file. - -# Add new inflection rules using the following format. Inflections -# are locale specific, and you may define rules for as many different -# locales as you wish. All of these examples are active by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end - -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end diff --git a/packages/edgestitch/spec/dummy/config/initializers/mime_types.rb b/packages/edgestitch/spec/dummy/config/initializers/mime_types.rb deleted file mode 100644 index 6e1d16f0..00000000 --- a/packages/edgestitch/spec/dummy/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf diff --git a/packages/edgestitch/spec/dummy/config/locales/en.yml b/packages/edgestitch/spec/dummy/config/locales/en.yml deleted file mode 100644 index cf9b342d..00000000 --- a/packages/edgestitch/spec/dummy/config/locales/en.yml +++ /dev/null @@ -1,33 +0,0 @@ -# Files in the config/locales directory are used for internationalization -# and are automatically loaded by Rails. If you want to use locales other -# than English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t 'hello' -# -# In views, this is aliased to just `t`: -# -# <%= t('hello') %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# The following keys must be escaped otherwise they will not be retrieved by -# the default I18n backend: -# -# true, false, on, off, yes, no -# -# Instead, surround them with single quotes. -# -# en: -# 'true': 'foo' -# -# To learn more, please read the Rails Internationalization guide -# available at https://guides.rubyonrails.org/i18n.html. - -en: - hello: "Hello world" From b5af16a52343295a08ae3ced58f853ef57e6db7d Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 18:51:28 -0300 Subject: [PATCH 30/32] Read instance vairables with attr_reader --- packages/edgestitch/lib/edgestitch/exporter.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/edgestitch/lib/edgestitch/exporter.rb b/packages/edgestitch/lib/edgestitch/exporter.rb index 6e98b700..befcc694 100644 --- a/packages/edgestitch/lib/edgestitch/exporter.rb +++ b/packages/edgestitch/lib/edgestitch/exporter.rb @@ -21,11 +21,11 @@ def self.export(engine, dump) def initialize(engine) @engine = engine @database_directory_path = engine.root.join("db") - @extra_tables_path = @database_directory_path.join("extra_tables") - @structure_file_path = @database_directory_path.join("structure-self.sql") + @extra_tables_path = database_directory_path.join("extra_tables") + @structure_file_path = database_directory_path.join("structure-self.sql") end - def export(dump, to: @structure_file_path) + def export(dump, to: structure_file_path) StringIO.open do |buffer| buffer.puts dump.export_tables(tables) buffer.puts @@ -36,7 +36,7 @@ def export(dump, to: @structure_file_path) def migrations @migrations ||= begin - migrations_glob = @database_directory_path.join("{migrate,migrate.archive}/*.rb") + migrations_glob = database_directory_path.join("{migrate,migrate.archive}/*.rb") Dir[migrations_glob] .map { |filename| File.basename(filename).to_i } .sort @@ -49,8 +49,10 @@ def tables private + attr_reader :database_directory_path, :extra_tables_path, :structure_file_path + def extra_tables - @extra_tables ||= @extra_tables_path.exist? ? @extra_tables_path.readlines.map(&:strip) : [] + @extra_tables ||= extra_tables_path.exist? ? extra_tables_path.readlines.map(&:strip) : [] end def component_tables From 364d8348ea237091629fd0b67d439d9cb3e38949 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Thu, 22 Dec 2022 18:54:31 -0300 Subject: [PATCH 31/32] Apply suggestions from code review Co-authored-by: Jill Klang --- packages/edgestitch/docs/README.md | 6 +++--- packages/edgestitch/edgestitch.gemspec | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/edgestitch/docs/README.md b/packages/edgestitch/docs/README.md index 123e1546..65686e92 100644 --- a/packages/edgestitch/docs/README.md +++ b/packages/edgestitch/docs/README.md @@ -64,7 +64,7 @@ require "edgestitch/railtie" ## Usage -Edgestitch will enhance the default rails tasks, so using nothing special has to be done in order to use it. Once edgestitch is correctly installed things should Just Work™️ as explained in the rails manual, but it will be generating `structure-self.sql` along with `structure.sql` files. **Important**: It's recommended that `structure.sql` files are added to `.gitignore`. +Edgestitch will enhance the default rails tasks, so nothing special has to be done in order to use it. Once edgestitch is correctly installed things should Just Work™️ as explained in the rails manual, but it will be generating `structure-self.sql` along with `structure.sql` files. **Important**: It's recommended that `structure.sql` files are added to `.gitignore`. # How does it work @@ -78,7 +78,7 @@ A model is owned by an engine when it inherits from the Engine's ApplicationMode ## Extra tables -Sometimes an external dependency brings in extra tables that are not defined in any `structure-self.sql`. To be part of the ecosystem, the new tables should be owned by the engine adding them. That can be done by adding these tables to `/db/extra_tables`. It's a simple text file with a list of table names that do not inherit from `::AplicationModel`, but are owned by that engine and should be included in its structure-self.sql. +When an external dependency brings in extra tables (i.e. acts_as_taggable) that are not defined in any `structure-self.sql`. To be part of the ecosystem, the new tables should be owned by the engine adding them. That can be done by adding these tables to `/db/extra_tables`. It's a simple text file with a list of table names that do not inherit from `::AplicationModel`, but are owned by that engine and should be included in its structure-self.sql. ## External Gems @@ -88,7 +88,7 @@ An external gem can also define a `structure-self.sql` file to be adapted in thi After 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. -To 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install this gem onto your local machine, run `bundle exec rake install`. ## Contributing diff --git a/packages/edgestitch/edgestitch.gemspec b/packages/edgestitch/edgestitch.gemspec index 1cb71ce9..b315d4b0 100644 --- a/packages/edgestitch/edgestitch.gemspec +++ b/packages/edgestitch/edgestitch.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |spec| spec.email = ["chjunior@gmail.com"] spec.description = spec.summary = "Edgestitch allows engines to define partial structure-self.sql files to be " \ - "stitched into a single structure.sql file by the umbrella application" + "stitched into a single structure.sql file by the umbrella application." spec.homepage = "https://github.com/powerhome/power-tools" spec.license = "MIT" spec.required_ruby_version = ">= 2.7" From 29d24aae47faccdeeafb4af1975be8950d636f15 Mon Sep 17 00:00:00 2001 From: Carlos Palhares Date: Tue, 27 Dec 2022 12:31:36 -0300 Subject: [PATCH 32/32] Make first release 0.1.0 --- packages/edgestitch/docs/CHANGELOG.md | 2 +- packages/edgestitch/lib/edgestitch/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edgestitch/docs/CHANGELOG.md b/packages/edgestitch/docs/CHANGELOG.md index 4d6f7808..84e49fe6 100644 --- a/packages/edgestitch/docs/CHANGELOG.md +++ b/packages/edgestitch/docs/CHANGELOG.md @@ -1,4 +1,4 @@ -## [1.0.0] - 2022-12-22 +## [0.1.0] - 2022-12-27 - First release of Edgestitch, extracted from NitroMysql. - Supports all rails >= 6.0 and all ruby >= 2.7 \ No newline at end of file diff --git a/packages/edgestitch/lib/edgestitch/version.rb b/packages/edgestitch/lib/edgestitch/version.rb index 6cd3f8e0..cb1a1f2b 100644 --- a/packages/edgestitch/lib/edgestitch/version.rb +++ b/packages/edgestitch/lib/edgestitch/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Edgestitch - VERSION = "1.0.0" + VERSION = "0.1.0" end