This code is failing on the last line specifically due to the check for table_exists? How do I correctly do this in Datamapper?
require 'sinatra'
require 'DataMapper'
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/blog.db")
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
property :created_at, DateTime
end
DataMapper.finalize
# automatically create the post table
DataMapper.auto_migrate! unless Post.table_exists?
Justin,
If you have
dm-migrationsrequired (which basically means that you’re using an RDBMS adapter anyway), you can do the following to find out if a table (or column inside that table) exists.Note that these API methods only get mixed into the
adapterifdm-migrationsare required and you’re using aDataObjectsAdapterdescendent.