kanal-plugins-active_record 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +129 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +17 -0
- data/kanal-plugins-active_record.gemspec +43 -0
- data/lib/kanal/plugins/active_record/active_record_plugin.rb +113 -0
- data/lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb +78 -0
- data/lib/kanal/plugins/active_record/overriden/version_suffix_migrator.rb +28 -0
- data/lib/kanal/plugins/active_record/tasks/migrate_task.rb +82 -0
- data/lib/kanal/plugins/active_record/version.rb +9 -0
- data/lib/kanal/plugins/active_record.rb +12 -0
- data/sig/kanal/plugins/active_record.rbs +8 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 546c978081c2d91ee71701cf81cbb505e5c4225aa65d060e3239f033153f219c
|
4
|
+
data.tar.gz: 3af59bef94b8a18163ee2f5f5e1d22788e0580eb27d2ff3c7234219666bf7862
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55b2a030d004ac0688a575443efac7e2ac20205515a5c32012620d71e45db730ddfa417ccac665960dd27c570a195a0f75404a9aaf727df00e8c8f5ff7f89fe1
|
7
|
+
data.tar.gz: 12d8dc5064323d5e6a4f8b348d51efc2d064b24f1e7140185bbe6996e4eea57a7f8b8822e9e0959d224fa918289cfe99d00b5772db6792bdcbd9a2360aaa7bb4
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.6
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at idchlife@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in kanal-plugins-active_record.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "kanal"
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "rubocop", "~> 1.21"
|
16
|
+
gem "ruby-debug-ide"
|
17
|
+
gem "solargraph"
|
18
|
+
gem "yard"
|
19
|
+
end
|
20
|
+
|
21
|
+
group :test do
|
22
|
+
gem "simplecov", require: false
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git@github.com:idchlife/kanal.git
|
3
|
+
revision: 5dbc20a3480337192d1193b0e569dba9d665d4c9
|
4
|
+
specs:
|
5
|
+
kanal (0.3.0)
|
6
|
+
|
7
|
+
PATH
|
8
|
+
remote: .
|
9
|
+
specs:
|
10
|
+
kanal-plugins-active_record (0.2.0)
|
11
|
+
activerecord
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activemodel (7.0.4.1)
|
17
|
+
activesupport (= 7.0.4.1)
|
18
|
+
activerecord (7.0.4.1)
|
19
|
+
activemodel (= 7.0.4.1)
|
20
|
+
activesupport (= 7.0.4.1)
|
21
|
+
activesupport (7.0.4.1)
|
22
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
|
+
i18n (>= 1.6, < 2)
|
24
|
+
minitest (>= 5.1)
|
25
|
+
tzinfo (~> 2.0)
|
26
|
+
ast (2.4.2)
|
27
|
+
backport (1.2.0)
|
28
|
+
benchmark (0.2.1)
|
29
|
+
concurrent-ruby (1.2.0)
|
30
|
+
diff-lcs (1.5.0)
|
31
|
+
docile (1.4.0)
|
32
|
+
e2mmap (0.1.0)
|
33
|
+
i18n (1.12.0)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
jaro_winkler (1.5.4)
|
36
|
+
json (2.6.3)
|
37
|
+
kramdown (2.4.0)
|
38
|
+
rexml
|
39
|
+
kramdown-parser-gfm (1.1.0)
|
40
|
+
kramdown (~> 2.0)
|
41
|
+
minitest (5.17.0)
|
42
|
+
nokogiri (1.14.0-x86_64-darwin)
|
43
|
+
racc (~> 1.4)
|
44
|
+
parallel (1.22.1)
|
45
|
+
parser (3.2.0.0)
|
46
|
+
ast (~> 2.4.1)
|
47
|
+
racc (1.6.2)
|
48
|
+
rainbow (3.1.1)
|
49
|
+
rake (13.0.6)
|
50
|
+
regexp_parser (2.6.2)
|
51
|
+
reverse_markdown (2.1.1)
|
52
|
+
nokogiri
|
53
|
+
rexml (3.2.5)
|
54
|
+
rspec (3.12.0)
|
55
|
+
rspec-core (~> 3.12.0)
|
56
|
+
rspec-expectations (~> 3.12.0)
|
57
|
+
rspec-mocks (~> 3.12.0)
|
58
|
+
rspec-core (3.12.0)
|
59
|
+
rspec-support (~> 3.12.0)
|
60
|
+
rspec-expectations (3.12.2)
|
61
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
+
rspec-support (~> 3.12.0)
|
63
|
+
rspec-mocks (3.12.3)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.12.0)
|
66
|
+
rspec-support (3.12.0)
|
67
|
+
rubocop (1.44.0)
|
68
|
+
json (~> 2.3)
|
69
|
+
parallel (~> 1.10)
|
70
|
+
parser (>= 3.2.0.0)
|
71
|
+
rainbow (>= 2.2.2, < 4.0)
|
72
|
+
regexp_parser (>= 1.8, < 3.0)
|
73
|
+
rexml (>= 3.2.5, < 4.0)
|
74
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
75
|
+
ruby-progressbar (~> 1.7)
|
76
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
77
|
+
rubocop-ast (1.24.1)
|
78
|
+
parser (>= 3.1.1.0)
|
79
|
+
ruby-debug-ide (0.7.3)
|
80
|
+
rake (>= 0.8.1)
|
81
|
+
ruby-progressbar (1.11.0)
|
82
|
+
simplecov (0.22.0)
|
83
|
+
docile (~> 1.1)
|
84
|
+
simplecov-html (~> 0.11)
|
85
|
+
simplecov_json_formatter (~> 0.1)
|
86
|
+
simplecov-html (0.12.3)
|
87
|
+
simplecov_json_formatter (0.1.4)
|
88
|
+
solargraph (0.48.0)
|
89
|
+
backport (~> 1.2)
|
90
|
+
benchmark
|
91
|
+
bundler (>= 1.17.2)
|
92
|
+
diff-lcs (~> 1.4)
|
93
|
+
e2mmap
|
94
|
+
jaro_winkler (~> 1.5)
|
95
|
+
kramdown (~> 2.3)
|
96
|
+
kramdown-parser-gfm (~> 1.1)
|
97
|
+
parser (~> 3.0)
|
98
|
+
reverse_markdown (>= 1.0.5, < 3)
|
99
|
+
rubocop (>= 0.52)
|
100
|
+
thor (~> 1.0)
|
101
|
+
tilt (~> 2.0)
|
102
|
+
yard (~> 0.9, >= 0.9.24)
|
103
|
+
sqlite3 (1.6.0-x86_64-darwin)
|
104
|
+
thor (1.2.1)
|
105
|
+
tilt (2.0.11)
|
106
|
+
tzinfo (2.0.5)
|
107
|
+
concurrent-ruby (~> 1.0)
|
108
|
+
unicode-display_width (2.4.2)
|
109
|
+
webrick (1.7.0)
|
110
|
+
yard (0.9.28)
|
111
|
+
webrick (~> 1.7.0)
|
112
|
+
|
113
|
+
PLATFORMS
|
114
|
+
x86_64-darwin-21
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
kanal!
|
118
|
+
kanal-plugins-active_record!
|
119
|
+
rake (~> 13.0)
|
120
|
+
rspec (~> 3.0)
|
121
|
+
rubocop (~> 1.21)
|
122
|
+
ruby-debug-ide
|
123
|
+
simplecov
|
124
|
+
solargraph
|
125
|
+
sqlite3
|
126
|
+
yard
|
127
|
+
|
128
|
+
BUNDLED WITH
|
129
|
+
2.3.19
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 idchlife
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Kanal::Plugins::ActiveRecord
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kanal/plugins/active_record`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add kanal-plugins-active_record
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install kanal-plugins-active_record
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
TODO: Write usage instructions here
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
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.
|
24
|
+
|
25
|
+
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).
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kanal-plugins-active_record. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/kanal-plugins-active_record/blob/main/CODE_OF_CONDUCT.md).
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
34
|
+
|
35
|
+
## Code of Conduct
|
36
|
+
|
37
|
+
Everyone interacting in the Kanal::Plugins::ActiveRecord project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kanal-plugins-active_record/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
13
|
+
|
14
|
+
require "active_record"
|
15
|
+
require_relative "./lib/kanal/plugins/active_record/tasks/migrate_task"
|
16
|
+
|
17
|
+
Kanal::Plugins::ActiveRecord::Tasks::MigrateTask.new
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/kanal/plugins/active_record/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "kanal-plugins-active_record"
|
7
|
+
spec.version = Kanal::Plugins::ActiveRecord::VERSION
|
8
|
+
spec.authors = ["idchlife"]
|
9
|
+
spec.email = ["idchlife@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Plugin enables ActiveRecord in Kanal"
|
12
|
+
spec.description = "This plugin-library allows developers to use ActiveRecord inside their bots"
|
13
|
+
spec.homepage = "https://github.com/kanal-plugins_active_record"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7.6"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/kanal-plugins_active_record"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/kanal-plugins_active_record"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_dependency "activerecord"
|
35
|
+
# spec.add_dependency "kanal"
|
36
|
+
spec.add_development_dependency "sqlite3"
|
37
|
+
|
38
|
+
# Uncomment to register a new dependency of your gem
|
39
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
40
|
+
|
41
|
+
# For more information and examples about making a new gem, check out our
|
42
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
43
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
require "active_record/schema"
|
5
|
+
require "kanal/core/plugins/plugin"
|
6
|
+
# require_relative "./overriden/version_suffix_migration_context"
|
7
|
+
|
8
|
+
module Kanal
|
9
|
+
module Plugins
|
10
|
+
module ActiveRecord
|
11
|
+
class ActiveRecordPlugin < Kanal::Core::Plugins::Plugin
|
12
|
+
attr_reader :connection_options
|
13
|
+
|
14
|
+
@@migration_directories = []
|
15
|
+
|
16
|
+
#
|
17
|
+
# <Description>
|
18
|
+
#
|
19
|
+
# @param [Hash<String, Object>] connection_data <description>
|
20
|
+
#
|
21
|
+
def initialize(connection_options)
|
22
|
+
super()
|
23
|
+
|
24
|
+
@connection_options = connection_options
|
25
|
+
|
26
|
+
clear_migration_directories
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
:active_record
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# @param [Kanal::Core::Core] core <description>
|
35
|
+
#
|
36
|
+
# @return [void] <description>
|
37
|
+
#
|
38
|
+
def setup(core)
|
39
|
+
::ActiveRecord::Base.establish_connection(**@connection_options)
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Just in case
|
44
|
+
#
|
45
|
+
# @return [void] <description>
|
46
|
+
#
|
47
|
+
def clear_migration_directories
|
48
|
+
@@migration_directories = {}
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Add migrations directory to the list of migrations for specific project
|
53
|
+
#
|
54
|
+
# @param [String] dir <description>
|
55
|
+
# @param [String] project_name name of project which will migrations belong to. NOT USED right now
|
56
|
+
#
|
57
|
+
# @return [void] <description>
|
58
|
+
#
|
59
|
+
def add_migrations_directory(dir_path, project_name: "default")
|
60
|
+
raise "Directory path #{dir_path} for migrations does not exist!" unless Dir.exist? dir_path
|
61
|
+
|
62
|
+
if !@@migration_directories.keys.include? project_name
|
63
|
+
@@migration_directories[project_name] = []
|
64
|
+
end
|
65
|
+
|
66
|
+
return if @@migration_directories[project_name].include? dir_path
|
67
|
+
|
68
|
+
@@migration_directories[project_name] << dir_path
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Migrating all the added migrations
|
73
|
+
#
|
74
|
+
# @return [void] <description>
|
75
|
+
#
|
76
|
+
def migrate
|
77
|
+
self.class.migrate
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Check if ActiveRecord connected
|
82
|
+
#
|
83
|
+
# @return [Boolean] <description>
|
84
|
+
#
|
85
|
+
def self.connected?
|
86
|
+
::ActiveRecord::Base.connected?
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# This class method allows for Rakefile to access migration directories
|
91
|
+
# NOTE: there maaaay be problems when somebody uses this plugin several times within one project, I guess?
|
92
|
+
# Not sure this will be the use case in the future.
|
93
|
+
#
|
94
|
+
# @return [Array<String>] list of migration directories
|
95
|
+
#
|
96
|
+
def self.migration_directories
|
97
|
+
@@migration_directories
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.migrate
|
101
|
+
@@migration_directories.each do |project_name, dir_path|
|
102
|
+
# Kanal::Plugins::ActiveRecord::Overriden::VersionSuffixMigrationContext.new(
|
103
|
+
# project_name,
|
104
|
+
::ActiveRecord::MigrationContext.new(
|
105
|
+
dir_path,
|
106
|
+
::ActiveRecord::Base.connection.schema_migration
|
107
|
+
).migrate
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
require_relative "./version_suffix_migrator"
|
5
|
+
|
6
|
+
module Kanal
|
7
|
+
module Plugins
|
8
|
+
module ActiveRecord
|
9
|
+
module Overriden
|
10
|
+
#
|
11
|
+
# NOTE: NOT USED. CONSERVATED DUE TO THE USELESS WAY OF NAMED MIGRATIONS
|
12
|
+
# IF PLUGIN WILL BE USED WITH RAILS (I suspect it will be common case scenario, because
|
13
|
+
# it's not enough to create bots, it will be very often coupled with Rails for: admin, analytics,
|
14
|
+
# bot + websites stack, with registration in both places, etc)
|
15
|
+
#
|
16
|
+
# Will not spend more time on this feature, if someone still
|
17
|
+
# wants to utilize named migrations here - you are welcome, please fire up a PR,
|
18
|
+
# we will look into it
|
19
|
+
#
|
20
|
+
# Thanks to the craftsmanship in Redmine repository
|
21
|
+
# I was able to learn how it creates named migration versions.
|
22
|
+
# And now we can create our own strategy alike
|
23
|
+
#
|
24
|
+
class VersionSuffixMigrationContext < ::ActiveRecord::MigrationContext
|
25
|
+
#
|
26
|
+
# Overriden constructor to save version suffix
|
27
|
+
#
|
28
|
+
# @param [String] version_suffix <description>
|
29
|
+
# @param [Array<String>, String] migration_paths <description>
|
30
|
+
# @param [::ActiveRecord::SchemaMigration] schema_migration <description>
|
31
|
+
#
|
32
|
+
def initialize(version_suffix, migration_paths, schema_migration = ::ActiveRecord::SchemaMigration)
|
33
|
+
@version_suffix = version_suffix
|
34
|
+
super(migration_paths, schema_migration)
|
35
|
+
end
|
36
|
+
|
37
|
+
def up(target_version = nil, &block)
|
38
|
+
selected_migrations = if block_given?
|
39
|
+
migrations.select(&block)
|
40
|
+
else
|
41
|
+
migrations
|
42
|
+
end
|
43
|
+
|
44
|
+
Kanal::Plugins::ActiveRecord::Overriden::VersionSuffixMigrator.new(
|
45
|
+
:up,
|
46
|
+
selected_migrations,
|
47
|
+
schema_migration,
|
48
|
+
target_version,
|
49
|
+
version_suffix: @version_suffix
|
50
|
+
).migrate
|
51
|
+
end
|
52
|
+
|
53
|
+
def migrations
|
54
|
+
lst = super
|
55
|
+
|
56
|
+
lst.map do |migration_proxy|
|
57
|
+
migration_proxy.version = "#{migration_proxy.version}_#{@version_suffix}"
|
58
|
+
|
59
|
+
migration_proxy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_all_versions
|
64
|
+
if schema_migration.table_exists?
|
65
|
+
schema_migration.all_versions.filter do |v|
|
66
|
+
v.include? @version_suffix
|
67
|
+
end.map do |v|
|
68
|
+
Integer(v.sub!(@version_suffix, ""), 10)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
[]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_record"
|
4
|
+
|
5
|
+
module Kanal
|
6
|
+
module Plugins
|
7
|
+
module ActiveRecord
|
8
|
+
module Overriden
|
9
|
+
#
|
10
|
+
# NOTE: NOT USED
|
11
|
+
#
|
12
|
+
class VersionSuffixMigrator < ::ActiveRecord::Migrator
|
13
|
+
def initialize(direction, migrations, schema_migration, target_version = nil, version_suffix: nil)
|
14
|
+
super(direction, migrations, schema_migration, target_version)
|
15
|
+
|
16
|
+
@verson_suffix = version_suffix
|
17
|
+
end
|
18
|
+
|
19
|
+
def record_version_state_after_migrating(version)
|
20
|
+
result = super
|
21
|
+
|
22
|
+
"#{result}_#{@version_suffix}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rake"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
require_relative "../active_record_plugin"
|
7
|
+
|
8
|
+
module Kanal
|
9
|
+
module Plugins
|
10
|
+
module ActiveRecord
|
11
|
+
module Tasks
|
12
|
+
class MigrateTask < ::Rake::TaskLib
|
13
|
+
def initialize(name = :kanal)
|
14
|
+
super()
|
15
|
+
|
16
|
+
desc "Run migrations for Kanal plugin for ActiveRecord with all added migration directories. Use --yes to execute without y/n question."
|
17
|
+
|
18
|
+
namespace name do
|
19
|
+
namespace :active_record do
|
20
|
+
task :migrate do |t, args|
|
21
|
+
options = {}
|
22
|
+
opts = OptionParser.new
|
23
|
+
opts.banner = "Usage: kanal:active_record:migrate [options]"
|
24
|
+
opts.on "-y", "--yes", "Don't ask for confirmation, just run migrations" do |y|
|
25
|
+
options[:yes] = y
|
26
|
+
end
|
27
|
+
|
28
|
+
args = opts.order! ARGV do
|
29
|
+
end
|
30
|
+
opts.parse!
|
31
|
+
|
32
|
+
execute_migration_task options[:yes]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute_migration_task(yes = false)
|
39
|
+
plugin = Kanal::Plugins::ActiveRecord::ActiveRecordPlugin
|
40
|
+
|
41
|
+
unless plugin.connected?
|
42
|
+
puts "ActiveRecord is not connected to the database.
|
43
|
+
Directive 🤖: You should execute this rake task with application or something that has
|
44
|
+
this plugin added and initialized (via setup method). In other words: how could I execute migrations,
|
45
|
+
if there is no connection to database? ðŸ˜"
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
migration_dirs = plugin.migration_directories
|
50
|
+
|
51
|
+
if migration_dirs.empty?
|
52
|
+
puts "There are no migration directories for migrating. 👀
|
53
|
+
Try adding them yourself or add some plugins with them! 😉"
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
unless yes
|
58
|
+
puts "You are about to execute #{migration_dirs.size} directories with migrations to execute.
|
59
|
+
Are you sure you want to execute them?
|
60
|
+
|
61
|
+
Please enter y or Y as yes, other values will be considered as no"
|
62
|
+
|
63
|
+
result = $stdin.gets.chomp
|
64
|
+
|
65
|
+
if result != "y" && result != "Y"
|
66
|
+
puts "Stopping migrations!"
|
67
|
+
return
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
puts "Executing migrations..."
|
73
|
+
|
74
|
+
plugin.migrate
|
75
|
+
|
76
|
+
puts "Done! 🥳"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kanal-plugins-active_record
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- idchlife
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This plugin-library allows developers to use ActiveRecord inside their
|
42
|
+
bots
|
43
|
+
email:
|
44
|
+
- idchlife@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".rspec"
|
50
|
+
- ".rubocop.yml"
|
51
|
+
- ".ruby-version"
|
52
|
+
- CHANGELOG.md
|
53
|
+
- CODE_OF_CONDUCT.md
|
54
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- kanal-plugins-active_record.gemspec
|
60
|
+
- lib/kanal/plugins/active_record.rb
|
61
|
+
- lib/kanal/plugins/active_record/active_record_plugin.rb
|
62
|
+
- lib/kanal/plugins/active_record/overriden/version_suffix_migration_context.rb
|
63
|
+
- lib/kanal/plugins/active_record/overriden/version_suffix_migrator.rb
|
64
|
+
- lib/kanal/plugins/active_record/tasks/migrate_task.rb
|
65
|
+
- lib/kanal/plugins/active_record/version.rb
|
66
|
+
- sig/kanal/plugins/active_record.rbs
|
67
|
+
homepage: https://github.com/kanal-plugins_active_record
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata:
|
71
|
+
allowed_push_host: https://rubygems.org
|
72
|
+
homepage_uri: https://github.com/kanal-plugins_active_record
|
73
|
+
source_code_uri: https://github.com/kanal-plugins_active_record
|
74
|
+
changelog_uri: https://github.com/kanal-plugins_active_record
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 2.7.6
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.1.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Plugin enables ActiveRecord in Kanal
|
94
|
+
test_files: []
|