diff --git a/.editorconfig b/.editorconfig index 538ba2b..a6e7d26 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,3 +3,7 @@ root = true [*] indent_style = tab indent_size = 2 + +[*.{yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..1de68b2 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,20 @@ +# GitHub Copilot Instructions + +## Use Agent Context + +When working on this project, consult the `agents.md` file for project-specific guidelines, architecture decisions, and development patterns. This file contains curated information that will help you make better decisions aligned with the project's goals and standards. + +If the file does not exist, you will need to install it, by running the following command: + +```bash +$ bundle install +$ bundle exec bake agent:context:install +``` + +This command will set up the necessary context files that help you understand the project structure, dependencies, and conventions. + +## Ignoring Files + +The `.gitignore` file is split into two sections, separated by a blank line. The first section is automatically generated, while the second section is user controlled. + +While working on pull requests, you should not add unrelated changes to the `.gitignore` file as part of the pull request. diff --git a/.github/workflows/documentation-coverage.yaml b/.github/workflows/documentation-coverage.yaml new file mode 100644 index 0000000..6d06003 --- /dev/null +++ b/.github/workflows/documentation-coverage.yaml @@ -0,0 +1,25 @@ +name: Documentation Coverage + +on: [push, pull_request] + +permissions: + contents: read + +env: + COVERAGE: PartialSummary + BUNDLE_WITH: maintenance + +jobs: + validate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler-cache: true + + - name: Validate coverage + timeout-minutes: 5 + run: bundle exec bake decode:index:coverage lib diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml new file mode 100644 index 0000000..a6013fc --- /dev/null +++ b/.github/workflows/documentation.yaml @@ -0,0 +1,58 @@ +name: Documentation + +on: + push: + branches: + - main + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages: +permissions: + contents: read + pages: write + id-token: write + +# Allow one concurrent deployment: +concurrency: + group: "pages" + cancel-in-progress: true + +env: + BUNDLE_WITH: maintenance + +jobs: + generate: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v7 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler-cache: true + + - name: Installing packages + run: sudo apt-get install wget + + - name: Generate documentation + timeout-minutes: 5 + run: bundle exec bake utopia:project:static --force no + + - name: Upload documentation artifact + uses: actions/upload-pages-artifact@v5 + with: + path: docs + + deploy: + runs-on: ubuntu-latest + + environment: + name: github-pages + url: ${{steps.deployment.outputs.page_url}} + + needs: generate + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v5 diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml deleted file mode 100644 index 4a4a663..0000000 --- a/.github/workflows/documentation.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Documentation - -on: - push: - branches: - - master - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 - env: - BUNDLE_WITH: maintenance - with: - ruby-version: 2.7 - bundler-cache: true - - - name: Installing packages - run: sudo apt-get install wget - - - name: Generate documentation - timeout-minutes: 5 - run: bundle exec bake utopia:project:static - - - name: Deploy documentation - uses: JamesIves/github-pages-deploy-action@4.0.0 - with: - branch: docs - folder: docs diff --git a/.github/workflows/rubocop.yaml b/.github/workflows/rubocop.yaml new file mode 100644 index 0000000..03e44d5 --- /dev/null +++ b/.github/workflows/rubocop.yaml @@ -0,0 +1,21 @@ +name: RuboCop + +on: [push, pull_request] + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler-cache: true + + - name: Run RuboCop + timeout-minutes: 10 + run: bundle exec rubocop diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..f13cdac --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,58 @@ +name: Test Coverage + +on: [push, pull_request] + +permissions: + contents: read + +env: + COVERAGE: PartialSummary + +jobs: + test: + name: ${{matrix.ruby}} on ${{matrix.os}} + runs-on: ${{matrix.os}}-latest + + strategy: + matrix: + os: + - ubuntu + - macos + + ruby: + - ruby + + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + bundler-cache: true + + - name: Run tests + timeout-minutes: 5 + run: bundle exec bake test + + - uses: actions/upload-artifact@v7 + with: + include-hidden-files: true + if-no-files-found: error + name: coverage-${{matrix.os}}-${{matrix.ruby}} + path: .covered.db + + validate: + needs: test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + bundler-cache: true + + - uses: actions/download-artifact@v8 + + - name: Validate coverage + timeout-minutes: 5 + run: bundle exec bake covered:validate --paths */.covered.db \; diff --git a/.github/workflows/development.yml b/.github/workflows/test.yaml similarity index 74% rename from .github/workflows/development.yml rename to .github/workflows/test.yaml index 3cf1d52..32501fa 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/test.yaml @@ -1,9 +1,13 @@ -name: Development +name: Test on: [push, pull_request] +permissions: + contents: read + jobs: test: + name: ${{matrix.ruby}} on ${{matrix.os}} runs-on: ${{matrix.os}}-latest continue-on-error: ${{matrix.experimental}} @@ -14,13 +18,11 @@ jobs: - macos ruby: - - 2.5 - - 2.6 - - 2.7 - - 3.0 + - "3.3" + - "3.4" + - "4.0" experimental: [false] - env: [""] include: - os: ubuntu @@ -34,12 +36,12 @@ jobs: experimental: true steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true - name: Run tests - timeout-minutes: 5 - run: ${{matrix.env}} bundle exec rspec + timeout-minutes: 10 + run: bundle exec bake test diff --git a/.gitignore b/.gitignore index 3f161f1..d53e569 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,7 @@ -/.bundle/ -/.yardoc +/agents.md +/.agents/ +/.bundle +/pkg /gems.locked -/_yardoc/ -/coverage/ -/doc/ -/pkg/ -/spec/reports/ -/tmp/ - -# rspec failure tracking -.rspec_status +/.covered.db +/external diff --git a/.rspec b/.rspec deleted file mode 100644 index 744a412..0000000 --- a/.rspec +++ /dev/null @@ -1,5 +0,0 @@ ---color ---format documentation ---backtrace ---require spec_helper ---warnings diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..0eeddec --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,109 @@ +plugins: + - rubocop-md + - rubocop-socketry + +AllCops: + DisabledByDefault: true + +# Socketry specific rules: + +Layout/ConsistentBlankLineIndentation: + Enabled: true + +Layout/BlockDelimiterSpacing: + Enabled: true + +Style/GlobalExceptionVariables: + Enabled: true + +# General Layout rules: + +Layout/IndentationStyle: + Enabled: true + EnforcedStyle: tabs + +Layout/InitialIndentation: + Enabled: true + +Layout/IndentationWidth: + Enabled: true + Width: 1 + +Layout/IndentationConsistency: + Enabled: true + EnforcedStyle: normal + +Layout/BlockAlignment: + Enabled: true + +Layout/EndAlignment: + Enabled: true + EnforcedStyleAlignWith: start_of_line + +Layout/BeginEndAlignment: + Enabled: true + EnforcedStyleAlignWith: start_of_line + +Layout/RescueEnsureAlignment: + Enabled: true + +Layout/ElseAlignment: + Enabled: true + +Layout/DefEndAlignment: + Enabled: true + +Layout/CaseIndentation: + Enabled: true + EnforcedStyle: end + +Layout/CommentIndentation: + Enabled: true + +Layout/FirstHashElementIndentation: + Enabled: true + EnforcedStyle: consistent + +Layout/EmptyLinesAroundClassBody: + Enabled: true + +Layout/EmptyLinesAroundModuleBody: + Enabled: true + +Layout/EmptyLineAfterMagicComment: + Enabled: true + +Layout/SpaceInsideBlockBraces: + Enabled: true + EnforcedStyle: no_space + SpaceBeforeBlockParameters: false + +Layout/SpaceAroundBlockParameters: + Enabled: true + EnforcedStyleInsidePipes: no_space + +Layout/FirstArrayElementIndentation: + Enabled: true + EnforcedStyle: consistent + +Layout/ArrayAlignment: + Enabled: true + EnforcedStyle: with_fixed_indentation + +Layout/FirstArgumentIndentation: + Enabled: true + EnforcedStyle: consistent + +Layout/ArgumentAlignment: + Enabled: true + EnforcedStyle: with_fixed_indentation + +Layout/ClosingParenthesisIndentation: + Enabled: true + +Style/FrozenStringLiteralComment: + Enabled: true + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes diff --git a/bake.rb b/bake.rb new file mode 100644 index 0000000..9441211 --- /dev/null +++ b/bake.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2025-2026, by Samuel Williams. + +# Update the project documentation with the new version number. +# +# @parameter version [String] The new version number. +def after_gem_release_version_increment(version) + context["releases:update"].call(version) + context["utopia:project:update"].call +end + +# Create a GitHub release for the given tag. +# +# @parameter tag [String] The tag to create a release for. +def after_gem_release(tag:, **options) + context["releases:github:release"].call(tag) +end diff --git a/bake/migrate.rb b/bake/migrate.rb index 8554811..41d43d7 100644 --- a/bake/migrate.rb +++ b/bake/migrate.rb @@ -1,7 +1,11 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2021, by Samuel Williams. # @parameter paths [Array] Only apply the specified migrations. def migrate(paths: nil) - require 'migrate/controller' + require "migrate/controller" controller = Migrate::Controller.new @@ -10,12 +14,12 @@ def migrate(paths: nil) # @parameter name [String] the path for the new migration. def create(name) - require 'migrate/controller' + require "migrate/controller" controller = Migrate::Controller.new path = controller.create!(name) do |file| - file.puts "\# migrate(...) do" + file.puts "\# migrate(target, using: Provider) do" file.puts "\# end" end diff --git a/config/sus.rb b/config/sus.rb new file mode 100644 index 0000000..cba4712 --- /dev/null +++ b/config/sus.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2026, by Samuel Williams. + +require "covered/sus" +include Covered::Sus diff --git a/spec/migrate/project/migrate/1_update_migration_names.rb b/fixtures/project/migrate/1_update_migration_names.rb similarity index 52% rename from spec/migrate/project/migrate/1_update_migration_names.rb rename to fixtures/project/migrate/1_update_migration_names.rb index f0aaf1d..f05e02c 100644 --- a/spec/migrate/project/migrate/1_update_migration_names.rb +++ b/fixtures/project/migrate/1_update_migration_names.rb @@ -1,3 +1,8 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. + migrate(Financier::DATABASE, using: DB::Migrate) do end diff --git a/spec/migrate/project/migrate/2_change_transaction_to_document.rb b/fixtures/project/migrate/2_change_transaction_to_document.rb similarity index 65% rename from spec/migrate/project/migrate/2_change_transaction_to_document.rb rename to fixtures/project/migrate/2_change_transaction_to_document.rb index 2326408..9233100 100644 --- a/spec/migrate/project/migrate/2_change_transaction_to_document.rb +++ b/fixtures/project/migrate/2_change_transaction_to_document.rb @@ -1,3 +1,7 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. def call(controller) paths = controller.root.glob("**/*.xnode") diff --git a/gems.rb b/gems.rb index 2ac09ce..c60a147 100644 --- a/gems.rb +++ b/gems.rb @@ -1,3 +1,8 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. + source "https://rubygems.org" gemspec @@ -8,3 +13,20 @@ gem "utopia-project" end + +gem "decode", "~> 0.30.0", group: :maintenance + +gem "rubocop", "~> 1.91", group: :test +gem "rubocop-md", "~> 2.0", group: :test +gem "rubocop-socketry", "~> 0.11.1", group: :test + +group :test do + gem "sus" + gem "covered" + gem "bake-test" +end + +# Moved Development Dependencies +gem "bake" + +gem "bake-releases", "~> 0.5.4", group: :maintenance diff --git a/lib/migrate.rb b/lib/migrate.rb index 95e00df..16943df 100644 --- a/lib/migrate.rb +++ b/lib/migrate.rb @@ -1,24 +1,9 @@ -# Copyright, 2017, by Samuel G. D. Williams. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# frozen_string_literal: true -require_relative 'migrate/version' +# Released under the MIT License. +# Copyright, 2017, by Samuel Williams. -require_relative 'migrate/controller' -require_relative 'migrate/migration' +require_relative "migrate/version" + +require_relative "migrate/controller" +require_relative "migrate/migration" diff --git a/lib/migrate/controller.rb b/lib/migrate/controller.rb index 73bfb44..e231602 100644 --- a/lib/migrate/controller.rb +++ b/lib/migrate/controller.rb @@ -1,32 +1,18 @@ -# Copyright, 2017, by Samuel G. D. Williams. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# frozen_string_literal: true -require 'console' -require 'build/files' +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. -require_relative 'migration' +require "console" +require "build/files" +require "pathname" + +require_relative "migration" module Migrate class Controller - def self.root - Build::Files::Path.current / "migrate" + def self.root(dir = Dir.pwd) + Pathname.new(dir) / "migrate" end def initialize(root = self.class.root) diff --git a/lib/migrate/migration.rb b/lib/migrate/migration.rb index 47502a3..1382fa6 100644 --- a/lib/migrate/migration.rb +++ b/lib/migrate/migration.rb @@ -1,22 +1,7 @@ -# Copyright, 2017, by Samuel G. D. Williams. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. module Migrate class Migration @@ -31,8 +16,8 @@ def call(controller) self.instance_eval(::File.read(@path), @path) end - def migrate(target, using:, &block) - using.migrate(self.name, target, &block) + def migrate(target, using:, name: self.name, **options, &block) + using.migrate(name, target, **options, &block) end def to_s diff --git a/lib/migrate/provider.rb b/lib/migrate/provider.rb index 77e6b4b..02a8b8b 100644 --- a/lib/migrate/provider.rb +++ b/lib/migrate/provider.rb @@ -1,23 +1,7 @@ -using.migrate(self.name, target, &block) -# Copyright, 2017, by Samuel G. D. Williams. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2021, by Samuel Williams. module Migrate class Provider diff --git a/lib/migrate/version.rb b/lib/migrate/version.rb index 61db40f..3ab2666 100644 --- a/lib/migrate/version.rb +++ b/lib/migrate/version.rb @@ -1,3 +1,7 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. module Migrate VERSION = "0.3.1" diff --git a/README.md b/license.md similarity index 54% rename from README.md rename to license.md index fe8caf2..de3ae1c 100644 --- a/README.md +++ b/license.md @@ -1,26 +1,6 @@ -# Migrate +# MIT License -Provides a generic set of tools to implement migrations. - -[![Development Status](https://github.com/ioquatix/migrate/workflows/Development/badge.svg)](https://github.com/ioquatix/migrate/actions?workflow=Development) - -## Usage - -Please see the [project documentation](https://socketry.github.io/migrate). - -## Contributing - -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - -## License - -Released under the MIT license. - -Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams). +Copyright, 2017-2021, by Samuel Williams. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -29,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/migrate.gemspec b/migrate.gemspec index 15ce007..45e1eb9 100644 --- a/migrate.gemspec +++ b/migrate.gemspec @@ -1,3 +1,4 @@ +# frozen_string_literal: true require_relative "lib/migrate/version" @@ -9,17 +10,20 @@ Gem::Specification.new do |spec| spec.authors = ["Samuel Williams"] spec.license = "MIT" + spec.cert_chain = ["release.cert"] + spec.signing_key = File.expand_path("~/.gem/release.pem") + spec.homepage = "https://github.com/socketry/migrate" spec.metadata = { + "bug_tracker_uri" => "https://github.com/socketry/migrate/issues", "funding_uri" => "https://github.com/sponsors/ioquatix/", + "source_code_uri" => "https://github.com/socketry/migrate.git", } - spec.files = Dir.glob('{bake,lib}/**/*', File::FNM_DOTMATCH, base: __dir__) + spec.files = Dir.glob(["{bake,lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__) - spec.add_dependency "build-files", "~> 1.7" + spec.required_ruby_version = ">= 3.3" - spec.add_development_dependency "bake" - spec.add_development_dependency "bundler" - spec.add_development_dependency "rspec", "~> 3.0" + spec.add_dependency "build-files", "~> 1.7" end diff --git a/migrate/20210522191946-hello_world.rb b/migrate/20210522191946-hello_world.rb index 934ae3a..5a9a2af 100644 --- a/migrate/20210522191946-hello_world.rb +++ b/migrate/20210522191946-hello_world.rb @@ -1,2 +1,4 @@ -# migrate(...) do -# end +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2021, by Samuel Williams. diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..90665f3 --- /dev/null +++ b/readme.md @@ -0,0 +1,47 @@ +# Migrate + +Provides a generic set of tools to implement migrations. + +[![Development Status](https://github.com/socketry/migrate/workflows/Test/badge.svg)](https://github.com/socketry/migrate/actions?workflow=Test) + +## Usage + +Please see the [project documentation](https://socketry.github.io/migrate). + +## Releases + +There are no documented releases. + +## Contributing + +We welcome contributions to this project. + +1. Fork the repository. +2. Create your feature branch (`git checkout -b my-new-feature`). +3. Commit your changes (`git commit -am 'Add some feature.'`). +4. Push to the branch (`git push origin my-new-feature`). +5. Create a new pull request. + +### Running Tests + +To run the test suite: + +``` bash +$ bundle exec sus +``` + +### Making Releases + +To make a new release: + +``` bash +$ bundle exec bake gem:release:patch # or minor or major +``` + +### Developer Certificate of Origin + +In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed. + +### Community Guidelines + +This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers. diff --git a/release.cert b/release.cert new file mode 100644 index 0000000..d98e595 --- /dev/null +++ b/release.cert @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11 +ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK +CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz +MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd +MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj +bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB +igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2 +9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW +sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE +e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN +XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss +RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn +tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM +zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW +xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O +BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs +aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs +aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE +cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl +xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/ +c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp +8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws +JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP +eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt +Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8 +voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg= +-----END CERTIFICATE----- diff --git a/releases.md b/releases.md new file mode 100644 index 0000000..eaa230e --- /dev/null +++ b/releases.md @@ -0,0 +1,3 @@ +# Releases + +## Unreleased diff --git a/spec/migrate/migrations_spec.rb b/spec/migrate/migrations_spec.rb deleted file mode 100644 index a0c176a..0000000 --- a/spec/migrate/migrations_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright, 2017, by Samuel G. D. Williams. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -RSpec.describe Migrate::Controller do - let(:root) {Build::Files::Path.join(__dir__, "project/migrate")} - subject(:controller) {described_class.new(root)} - - it "can list migrations" do - expect(controller.migrations).to_not be_empty - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index beb82de..0000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -require "bundler/setup" -require "migrate" - -RSpec.configure do |config| - # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" - - config.expect_with :rspec do |c| - c.syntax = :expect - end -end diff --git a/test/migrate/migrations.rb b/test/migrate/migrations.rb new file mode 100644 index 0000000..a902b8f --- /dev/null +++ b/test/migrate/migrations.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2017-2021, by Samuel Williams. + +require "migrate" +require "tmpdir" + +class FakeMigrator + def self.migrate(name, target, **options, &block) + @call = [name, target, options, block&.call] + end + + def self.call + @call + end +end + +describe Migrate::Controller do + let(:root) {Build::Files::Path.join(__dir__, "../../fixtures/project/migrate")} + let(:controller) {subject.new(root)} + + it "can list migrations" do + expect(controller.migrations).not.to be(:empty?) + end + + it "has a default root" do + expect(subject.root.to_s).to be =~ /migrate$/ + end + + with "temporary migration root" do + around do |&block| + Dir.mktmpdir do |root| + @root = Build::Files::Path.new(root) + block.call + end + end + + let(:controller) {subject.new(@root)} + + def write_migration(name, content) + path = @root / name + path.parent.mkpath + ::File.write(path, content) + path + end + + it "can create a migration" do + path = controller.create!("create_users") do |file| + file.write("# migration\n") + end + + expect(path.basename.to_s).to be =~ /\A\d{14}-create_users\.rb\z/ + expect(path.read).to be == "# migration\n" + end + + it "can apply migrations" do + marker = @root / "marker.txt" + write_migration("1_test_migration.rb", "File.write(#{marker.to_s.dump}, self.to_s)\n") + + controller.migrate! + + expect(marker.read).to be == "1_test_migration.rb" + end + + it "can invoke a migrator" do + path = write_migration("2_test_migration.rb", "") + migration = Migrate::Migration.new(path) + + migration.migrate(:database, using: FakeMigrator, mode: :test) do + :result + end + + expect(FakeMigrator.call).to be == ["2_test_migration.rb", :database, {mode: :test}, :result] + end + + it "can override the migration name" do + path = write_migration("3_test_migration.rb", "") + migration = Migrate::Migration.new(path) + + migration.migrate(:database, using: FakeMigrator, name: "custom_name") do + :result + end + + expect(FakeMigrator.call).to be == ["custom_name", :database, {}, :result] + end + end +end