-
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.
- Update README with instructions to config application and setup database; - Add money gem to handle financial values; - Add DATABASE_URL as required environment variable; - Add fake data for development/test purposes; - Configure sequel to handle database migrations; - Add golang as development dependency to running local services; - Add Procfile to start/stop related services; - Create custom tasks to handle postgres database;
- Loading branch information
1 parent
3366193
commit dfa934b
Showing
18 changed files
with
296 additions
and
6 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
APP_ENV=development | ||
DATABASE_URL=postgresql://postgres:@127.0.0.1/auction_fun_core_development?pool=10 |
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 +1,2 @@ | ||
APP_ENV=test | ||
DATABASE_URL=postgresql://postgres:@127.0.0.1:5432/auction_fun_core_test?pool=10 |
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 +1,3 @@ | ||
ruby 3.3.0 | ||
postgres 16.1 | ||
golang 1.21.5 |
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
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
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 @@ | ||
database: postgres |
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
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,10 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'config/application' | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
require "standard/rake" | ||
|
||
Dir.glob("#{File.expand_path(__dir__)}/lib/tasks/**/*.rake").each { |f| load f } | ||
|
||
task default: %i[spec standard] |
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
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
ROM::SQL.migration do | ||
up do | ||
run 'CREATE EXTENSION "unaccent"' | ||
run 'CREATE EXTENSION "hstore"' | ||
end | ||
|
||
down do | ||
run 'DROP EXTENSION IF EXISTS "unaccent"' | ||
run 'DROP EXTENSION IF EXISTS "hstore"' | ||
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 @@ | ||
# frozen_string_literal: true | ||
|
||
# This file should contain all the record creation needed to seed the development database with its default values. |
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,72 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rom-sql' | ||
require 'rom/sql/rake_task' | ||
require 'pry' | ||
require 'uri' | ||
|
||
namespace :auction_fun_core do | ||
namespace :db do | ||
uri = URI.parse(ENV.fetch('DATABASE_URL')) | ||
@database_name = (uri.path || '').split('/').last | ||
@database_host = uri.host | ||
|
||
desc 'Perform migration reset (full erase and migration up)' | ||
task :rom_configuration do | ||
Rake::Task['auction_fun_core:db:setup'].invoke | ||
end | ||
|
||
desc 'Prepare database for running migrations' | ||
task :setup do | ||
AuctionFunCore::Application.start(:db) | ||
ROM::SQL::RakeSupport.env = ROM.container(AuctionFunCore::Application[:db_config]) | ||
end | ||
|
||
desc 'Perform migration reset (full erase and migration up)' | ||
task reset: :rom_configuration do | ||
ROM::SQL::RakeSupport.run_migrations(target: 0) | ||
ROM::SQL::RakeSupport.run_migrations | ||
puts '<= db:reset executed' | ||
end | ||
|
||
desc 'Create a postgres database' | ||
task :create_database, [:userdb] do |_t, args| | ||
command = "CREATE DATABASE #{@database_name} LOCALE 'en_US.utf8' ENCODING UTF8 TEMPLATE template0;" | ||
|
||
sh %(psql -h #{@database_host} -U #{args[:userdb]} -c "#{command}") | ||
end | ||
|
||
desc 'Drop a postgres database' | ||
task :drop_database, [:userdb] do |_t, args| | ||
sh %(psql -h #{@database_host} -U #{args[:userdb]} -c "DROP DATABASE #{@database_name};") | ||
end | ||
|
||
desc 'Migrate the database (options [version_number])]' | ||
task :migrate, [:version] => :rom_configuration do |_, args| | ||
version = args[:version] | ||
|
||
if version.nil? | ||
ROM::SQL::RakeSupport.run_migrations | ||
puts '<= db:migrate executed' | ||
else | ||
ROM::SQL::RakeSupport.run_migrations(target: version.to_i) | ||
puts "<= db:migrate version=[#{version}] executed" | ||
end | ||
end | ||
|
||
desc 'Perform migration down (removes all tables)' | ||
task clean: :rom_configuration do | ||
ROM::SQL::RakeSupport.run_migrations(target: 0) | ||
puts '<= db:clean executed' | ||
end | ||
|
||
desc 'Seed data' | ||
task :seed_database do | ||
Rake::Task['auction_fun_core:db:setup'].invoke | ||
seed_file = AuctionFunCore::Application.root.join('db', 'seeds.rb') | ||
raise 'You tried to load seed data, but no seed loader is specified' unless seed_file | ||
|
||
load(seed_file) | ||
end | ||
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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
if defined?(Faker) | ||
I18n.enforce_available_locales = false | ||
Faker::Config.locale = 'pt-BR' | ||
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
Oops, something went wrong.