-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from performant-software/feature/udf1_migration
UDF #1 - Migration
- Loading branch information
Showing
20 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/.bundle/ | ||
/doc/ | ||
/log/*.log | ||
/pkg/ | ||
/tmp/ | ||
/test/dummy/db/*.sqlite3 | ||
/test/dummy/db/*.sqlite3-* | ||
/test/dummy/log/*.log | ||
/test/dummy/storage/ | ||
/test/dummy/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
source "https://rubygems.org" | ||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
||
# Specify your gem's dependencies in user_defined_fields.gemspec. | ||
gemspec | ||
|
||
gem "sqlite3" | ||
|
||
gem "sprockets-rails" | ||
|
||
# Start debugger with binding.b [https://github.com/ruby/debug] | ||
# gem "debug", ">= 1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright 2022 Performant Software Solutions, LLC | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,47 @@ | ||
# user-defined-fields | ||
Allow users to decide what data to capture | ||
# UserDefinedFields | ||
This gem is designed to serve and storage and configuration for allowing CMS users to dynamically define fields for their models. | ||
|
||
## Installation | ||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'user_defined_fields' | ||
``` | ||
|
||
And then execute: | ||
```bash | ||
$ bundle install | ||
``` | ||
|
||
Or install it yourself as: | ||
```bash | ||
$ gem install user_defined_fields | ||
``` | ||
|
||
## Usage | ||
|
||
#### Migrations | ||
To install the `user_defined` column on a model, use the following command: | ||
|
||
```bash | ||
bundle exec rails generate user_defined_fields:install my_model | ||
``` | ||
|
||
This will generate the following migration: | ||
|
||
```ruby | ||
class InstallUserDefinedFieldsOnMyModel < ActiveRecord::Migration[7.0] | ||
def up | ||
add_column :my_model, :user_defined, :jsonb, default: {} | ||
add_index :my_model, :user_defined, using: :gin | ||
end | ||
|
||
def down | ||
remove_index :my_model, :user_defined | ||
remove_column :my_model, :user_defined | ||
end | ||
end | ||
``` | ||
|
||
## License | ||
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "bundler/setup" | ||
|
||
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) | ||
load "rails/tasks/engine.rake" | ||
|
||
load "rails/tasks/statistics.rake" | ||
|
||
require "bundler/gem_tasks" |
Empty file.
4 changes: 4 additions & 0 deletions
4
app/controllers/user_defined_fields/application_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module UserDefinedFields | ||
class ApplicationController < ActionController::API | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module UserDefinedFields | ||
class ApplicationJob < ActiveJob::Base | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module UserDefinedFields | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: "[email protected]" | ||
layout "mailer" | ||
end | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module UserDefinedFields | ||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
# This command will automatically be run when you run "rails" with Rails gems | ||
# installed from the root of your application. | ||
|
||
ENGINE_ROOT = File.expand_path("..", __dir__) | ||
ENGINE_PATH = File.expand_path("../lib/user_defined_fields/engine", __dir__) | ||
APP_PATH = File.expand_path("../test/dummy/config/application", __dir__) | ||
|
||
# Set up gems listed in the Gemfile. | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) | ||
|
||
require "rails/all" | ||
require "rails/engine/commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
UserDefinedFields::Engine.routes.draw do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'rails/generators/active_record' | ||
|
||
module UserDefinedFields | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
# Includes | ||
include ActiveRecord::Generators::Migration | ||
|
||
# Command arguments | ||
argument :model_name, type: :string | ||
|
||
# Migration template directory | ||
source_root File.join(__dir__, 'templates') | ||
|
||
def copy_migration | ||
migration_template( | ||
'install.rb', | ||
"db/migrate/install_user_defined_fields_on_#{model_name}.rb", | ||
migration_version: migration_version, | ||
model_name: model_name | ||
) | ||
end | ||
|
||
def migration_version | ||
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
lib/generators/user_defined_fields/templates/install.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %> | ||
def up | ||
add_column :<%= model_name %>, :user_defined, :jsonb, default: {} | ||
add_index :<%= model_name %>, :user_defined, using: :gin | ||
end | ||
|
||
def down | ||
remove_index :<%= model_name %>, :user_defined | ||
remove_column :<%= model_name %>, :user_defined | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :user_defined_fields do | ||
# # Task goes here | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "user_defined_fields/version" | ||
require "user_defined_fields/engine" | ||
|
||
module UserDefinedFields | ||
# Your code goes here... | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module UserDefinedFields | ||
class Engine < ::Rails::Engine | ||
isolate_namespace UserDefinedFields | ||
config.generators.api_only = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module UserDefinedFields | ||
VERSION = "0.1.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require_relative 'lib/user_defined_fields/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'user_defined_fields' | ||
spec.version = UserDefinedFields::VERSION | ||
spec.authors = ['Performant Software Solutions'] | ||
spec.email = ['[email protected]'] | ||
spec.homepage = 'https://github.com/performant-software/user-defined-fields' | ||
spec.summary = 'Metadata made easy.' | ||
spec.description = 'A gem to empower users to define their own metadata.' | ||
spec.license = 'MIT' | ||
|
||
spec.metadata['homepage_uri'] = spec.homepage | ||
spec.metadata['source_code_uri'] = 'https://github.com/performant-software/user-defined-fields' | ||
|
||
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md'] | ||
end | ||
|
||
spec.add_dependency 'rails', '>= 6.0.3.2', '< 8' | ||
end |