Skip to content

Instantly share code, notes, and snippets.

@r7kamura
Created December 16, 2019 09:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r7kamura/7912fd2e9d92589486c6092be1b1f4f0 to your computer and use it in GitHub Desktop.
Save r7kamura/7912fd2e9d92589486c6092be1b1f4f0 to your computer and use it in GitHub Desktop.
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'activerecord', '6.0.0'
gem 'sqlite3'
end
require 'active_record'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.default_timezone = :local
ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.time :woke_up_at, default: '07:00:00', null: false
end
end
class User < ActiveRecord::Base
end
p User.create!
@r7kamura
Copy link
Author

$ ruby active_record_time_default.rb
-- create_table(:users, {:force=>true})
D, [2019-12-16T18:42:32.205868 #75481] DEBUG -- :    (0.7ms)  SELECT sqlite_version(*)
D, [2019-12-16T18:42:32.206242 #75481] DEBUG -- :    (0.1ms)  DROP TABLE IF EXISTS "users"
D, [2019-12-16T18:42:32.207009 #75481] DEBUG -- :    (0.4ms)  CREATE TABLE "users" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "woke_up_at" time DEFAULT '2000-01-01 07:00:00' NOT NULL)
   -> 0.0074s
D, [2019-12-16T18:42:32.242970 #75481] DEBUG -- :    (0.2ms)  CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL)
D, [2019-12-16T18:42:32.251669 #75481] DEBUG -- :   ActiveRecord::InternalMetadata Load (0.8ms)  SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?  [["key", "environment"], ["LIMIT", 1]]
D, [2019-12-16T18:42:32.254338 #75481] DEBUG -- :    (0.0ms)  begin transaction
D, [2019-12-16T18:42:32.254638 #75481] DEBUG -- :   ActiveRecord::InternalMetadata Create (0.1ms)  INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["key", "environment"], ["value", "default_env"], ["created_at", "2019-12-16 18:42:32.254092"], ["updated_at", "2019-12-16 18:42:32.254092"]]
D, [2019-12-16T18:42:32.254814 #75481] DEBUG -- :    (0.0ms)  commit transaction
D, [2019-12-16T18:42:32.256819 #75481] DEBUG -- :    (0.0ms)  begin transaction
D, [2019-12-16T18:42:32.256982 #75481] DEBUG -- :   User Create (0.1ms)  INSERT INTO "users" DEFAULT VALUES
D, [2019-12-16T18:42:32.257209 #75481] DEBUG -- :    (0.0ms)  commit transaction
#<User id: 1, woke_up_at: 2000-01-01 07:00:00 +0900>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment