diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd07414 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +alphadex.db diff --git a/Gemfile b/Gemfile index 68d2441..f2479d5 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gem "sequel" +gem "sqlite3" group :dev do gem "minitest" diff --git a/Gemfile.lock b/Gemfile.lock index 6a71ebb..6a5c349 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,7 @@ GEM rake (13.0.6) sequel (5.73.0) bigdecimal + sqlite3 (1.6.8-arm64-darwin) PLATFORMS arm64-darwin-22 @@ -14,6 +15,7 @@ DEPENDENCIES minitest rake sequel + sqlite3 BUNDLED WITH 2.4.1 diff --git a/Rakefile b/Rakefile index b0ec822..981c69f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,17 @@ +require "logger" + require "minitest/test_task" Minitest::TestTask.create + +namespace :db do + desc "Run migrations" + task :migrate, [:version] do |t, args| + require "sequel/core" + Sequel.extension :migration + version = args[:version].to_i if args[:version] + Sequel.connect(ENV.fetch("DATABASE_URL"), logger: Logger.new($stderr)) do |db| + Sequel::Migrator.run(db, "db/migrations", target: version) + end + end +end diff --git a/db/migrations/001_create_entities.rb b/db/migrations/001_create_entities.rb new file mode 100644 index 0000000..d93bb2e --- /dev/null +++ b/db/migrations/001_create_entities.rb @@ -0,0 +1,10 @@ +Sequel.migration do + change do + create_table(:entities) do + primary_key :id + + DateTime :created_at + DateTime :modified_at + end + end +end