Last active
September 19, 2022 07:25
-
-
Save pioz/156ec1d0f37008f819f55f5abac137f7 to your computer and use it in GitHub Desktop.
Active Record in script
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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'activerecord' | |
gem 'pg' | |
end | |
require 'active_record' | |
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
end | |
class Post < ApplicationRecord | |
end | |
def migrate | |
ActiveRecord::Schema.define do | |
create_table(:posts) do |t| | |
t.string :name | |
t.string :column1 | |
t.string :column2 | |
t.string :column3 | |
t.jsonb :data | |
end | |
end | |
end | |
migrate | |
records = 1_000_000.times.map do |i| | |
{ name: "foo#{i}", column1: 'value1', column2: 'value2', column3: 'value3', data: ['IT', 'FR'] } | |
end | |
Post.insert_all(records) | |
Post.create!(name: 'foo yeah', column1: 'value1', column2: 'value2', column3: 'value3', data: ['foo', 'FR']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment