Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/ruby-rails-migrator/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.0
5 changes: 5 additions & 0 deletions examples/ruby-rails-migrator/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "rails", "~> 7.1.0"
gem "pg"
gem "puma"
6 changes: 6 additions & 0 deletions examples/ruby-rails-migrator/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ApplicationController < ActionController::API
end
7 changes: 7 additions & 0 deletions examples/ruby-rails-migrator/app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked

# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
end
3 changes: 3 additions & 0 deletions examples/ruby-rails-migrator/app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
Empty file.
Empty file.
Empty file.
Empty file.
44 changes: 44 additions & 0 deletions examples/ruby-rails-migrator/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_relative "boot"

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
# require "active_storage/engine"
require "action_controller/railtie"
# require "action_mailer/railtie"
# require "action_mailbox/engine"
# require "action_text/engine"
require "action_view/railtie"
# require "action_cable/engine"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module RubyRailsMigrator
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 7.1

# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w(assets tasks))

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

# Only loads a smaller set of middleware suitable for API only apps.
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
end
end
4 changes: 4 additions & 0 deletions examples/ruby-rails-migrator/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)

require "bundler/setup" # Set up gems listed in the Gemfile.
require "bootsnap/setup" if ENV["BOOTSNAP_CACHE_DIR"] # Speed up boot time by caching expensive operations.
11 changes: 11 additions & 0 deletions examples/ruby-rails-migrator/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: <%= ENV["DB_HOST"] %>
database: <%= ENV["DB_NAME"] %>
username: <%= ENV["DB_USER"] %>
password: <%= ENV["DB_PASSWORD"] %>

production:
<<: *default
5 changes: 5 additions & 0 deletions examples/ruby-rails-migrator/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Load the Rails application.
require_relative "application"

# Initialize the Rails application.
Rails.application.initialize!
14 changes: 14 additions & 0 deletions examples/ruby-rails-migrator/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.enable_reloading = true
config.eager_load = false
config.consider_all_requests_local = true
config.server_timing = true
config.active_storage.service = :local
config.active_support.deprecation = :log
config.active_support.disallowed_deprecation = :raise
config.active_support.disallowed_deprecation_log_level = :info
config.active_record.migration_error = :page_load
config.active_record.verbose_query_logs = true
end
11 changes: 11 additions & 0 deletions examples/ruby-rails-migrator/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "rails/all"

module RubyRailsMigrator
class Application < Rails::Application
config.enable_reloading = false
config.eager_load = true
config.consider_all_requests_local = false
config.active_support.report_deprecations = false
config.active_record.dump_schema_after_migration = false
end
end
13 changes: 13 additions & 0 deletions examples/ruby-rails-migrator/config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.enable_reloading = false
config.eager_load = ENV["CI"].present?
config.public_file_server.enabled = true
config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" }
config.consider_all_requests_local = true
config.active_storage.service = :test
config.active_support.deprecation = :stderr
config.active_support.disallowed_deprecation = :raise
config.active_support.disallowed_deprecation_log_level = :info
end
2 changes: 2 additions & 0 deletions examples/ruby-rails-migrator/config/initializers/assets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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

# Rails.application.config.content_security_policy_nonce_generator = ->(request) { SecureRandom.base64(16) }
# Rails.application.config.content_security_policy_nonce_directives = %w(script-src style-src)
# Rails.application.config.content_security_policy_report_only = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Configure parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [
:passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn
]
16 changes: 16 additions & 0 deletions examples/ruby-rails-migrator/config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format. Inflections
# are locale-dependent, and can be localized as you see fit.
# 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

# Add new inflection rules using the following format. Inflections
# are locale-dependent, and can be localized as you see fit.
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym "RESTful"
# end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Rails.application.config.permissions_policy do |f|
# f.camera :none
# f.gyroscope :none
# f.microphone :none
# f.usb :none
# f.fullscreen :self
# f.payment :self, "https://secure.example.com"
# end
2 changes: 2 additions & 0 deletions examples/ruby-rails-migrator/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en:
hello: "Hello world"
8 changes: 8 additions & 0 deletions examples/ruby-rails-migrator/config/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count

port ENV.fetch("PORT") { 3000 }
environment ENV.fetch("RAILS_ENV") { "development" }
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }

plugin :tmp_restart
10 changes: 10 additions & 0 deletions examples/ruby-rails-migrator/config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check

# Defines the root path route ("/")
# root "posts#index"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name
t.string :email

t.timestamps
end
end
end
9 changes: 9 additions & 0 deletions examples/ruby-rails-migrator/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Example:
#
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
28 changes: 28 additions & 0 deletions examples/ruby-rails-migrator/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative "config/environment"
require "json"

def handler(event:, context:)
puts "Event: #{event.inspect}"

puts "Running migrations..."

# Ensure Rails logs to stdout
Rails.logger = Logger.new(STDOUT)

# Run migrations via ActiveRecord
ActiveRecord::Tasks::DatabaseTasks.migrate

puts "Migrations complete!"

{
statusCode: 200,
body: JSON.generate({ message: "Migrations completed successfully" })
}
rescue => e
puts "Migration failed: #{e.message}"
puts e.backtrace.join("\n")
{
statusCode: 500,
body: JSON.generate({ error: e.message, backtrace: e.backtrace })
}
end
Empty file.
66 changes: 66 additions & 0 deletions examples/ruby-rails-migrator/public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}

.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top: rgba(0, 0, 0, 0.05) solid 1px;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body class="rails-default-error-page">
<!-- This file lives in public/404.html -->
<div class="dialog">
<div>
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
66 changes: 66 additions & 0 deletions examples/ruby-rails-migrator/public/422.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<title>The change you wanted was rejected (422)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.rails-default-error-page {
background-color: #EFEFEF;
color: #2E2F30;
text-align: center;
font-family: arial, sans-serif;
margin: 0;
}

.rails-default-error-page div.dialog {
width: 95%;
max-width: 33em;
margin: 4em auto 0;
}

.rails-default-error-page div.dialog > div {
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #BBB;
border-top: #B00100 solid 4px;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
background-color: white;
padding: 7px 12% 0;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}

.rails-default-error-page h1 {
font-size: 100%;
color: #730E15;
line-height: 1.5em;
}

.rails-default-error-page div.dialog > p {
margin: 0 0 1em;
padding: 1em;
background-color: #F7F7F7;
border: 1px solid #CCC;
border-right-color: #999;
border-left-color: #999;
border-bottom-color: #999;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-top: rgba(0, 0, 0, 0.05) solid 1px;
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
}
</style>
</head>

<body class="rails-default-error-page">
<!-- This file lives in public/422.html -->
<div class="dialog">
<div>
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
<p>If you are the application owner check the logs for more information.</p>
</div>
</body>
</html>
Loading