· 8 years ago · Jul 10, 2018, 02:48 PM
1require 'rubygems'
2require 'dm-core'
3data_dir = "."
4
5DataMapper::Logger.new(STDOUT, :debug)
6DataMapper.setup(:default, "sqlite3::memory:")
7DataMapper.setup(:production, "sqlite3::memory:")
8
9class Bank
10 include DataMapper::Resource
11
12 DataMapper.repository(:default) do
13 property :cert, Integer, :key => true
14 property :new_cert, Integer
15 property :parent_cert, Integer
16 end
17
18 DataMapper.repository(:production) do
19 property :id, Serial
20 property :url, String
21 end
22end
23
24Bank.auto_migrate!(:default)
25Bank.auto_migrate!(:production)
26
27if $0 == __FILE__
28 puts "Development repo"
29 Bank.properties(:default).each {|x| puts x.inspect }
30 puts "Production repo"
31 Bank.properties(:production).each {|x| puts x.inspect }
32end
33
34# mungo:snippets snusnu$ ruby 991.rb
35# ~ (0.000160) SELECT sqlite_version(*)
36# ~ (0.000102) DROP TABLE IF EXISTS "banks"
37# ~ (0.000030) PRAGMA table_info("banks")
38# ~ (0.000286) CREATE TABLE "banks" ("cert" INTEGER NOT NULL, "new_cert" INTEGER, "parent_cert" INTEGER, PRIMARY KEY("cert"))
39# ~ (0.000014) SELECT sqlite_version(*)
40# ~ (0.000090) DROP TABLE IF EXISTS "banks"
41# ~ (0.000009) PRAGMA table_info("banks")
42# ~ (0.000201) CREATE TABLE "banks" ("cert" INTEGER NOT NULL, "new_cert" INTEGER, "parent_cert" INTEGER, "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "url" VARCHAR(50))
43# Development repo
44# #<DataMapper::Property @model=Bank @name=:cert>
45# #<DataMapper::Property @model=Bank @name=:new_cert>
46# #<DataMapper::Property @model=Bank @name=:parent_cert>
47# Production repo
48# #<DataMapper::Property @model=Bank @name=:cert>
49# #<DataMapper::Property @model=Bank @name=:new_cert>
50# #<DataMapper::Property @model=Bank @name=:parent_cert>
51# #<DataMapper::Property @model=Bank @name=:id>
52# #<DataMapper::Property @model=Bank @name=:url>