Class: DataStore
- Inherits:
-
Object
- Object
- DataStore
- Defined in:
- lib/trophy_scraper/data_store.rb
Constant Summary collapse
- @@DB_VERSION =
1
Instance Method Summary collapse
-
#initialize(connection_string, logger_level, logger_dest) ⇒ DataStore
constructor
A new instance of DataStore.
Constructor Details
#initialize(connection_string, logger_level, logger_dest) ⇒ DataStore
Returns a new instance of DataStore.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/trophy_scraper/data_store.rb', line 3 def initialize(connection_string, logger_level, logger_dest) DataMapper::Logger.new(logger_dest, logger_level) DataMapper.setup(:default, connection_string) begin = Meta.get("version") rescue #TODO, only eat the table not found error end if == nil $logger.info("Database is empty, creating schema.") DataMapper.auto_migrate! = Meta.new(:name => "version", :value => @@DB_VERSION) .save insert_reference_data elsif .value.to_i < @@DB_VERSION $logger.info("Database schema version is older than code's, gracefully updating.") DataMapper.auto_upgrade! .value = @@DB_VERSION .save elsif .value.to_i > @@DB_VERSION #TODO Code is older than db, warn and abort. $logger.warn("Database schema version is newer than code's, aborting.") else $logger.info("Database schema is up to date.") end end |