Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9051805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:00:12+00:00 2026-06-16T13:00:12+00:00

I’m building a small web app using sinatra + datamapper. The app is based

  • 0

I’m building a small web app using sinatra + datamapper. The app is based on an sqlite database which contains a big number of records in table1 and nothing in table2.

My dir structure is the following:

total 32
-rw-r--r--   1 atma  staff  1895 31 Δεκ 21:35 application.rb
drwxr-xr-x   6 atma  staff   204 31 Δεκ 21:10 archive/
-rw-r--r--@  1 atma  staff    82 23 Δεκ 23:59 config.ru
drwxr-xr-x  10 atma  staff   340 31 Δεκ 21:38 lib/
drwxr-xr-x   4 atma  staff   136 27 Δεκ 20:01 public/
drwxr-xr-x   6 atma  staff   204 24 Δεκ 00:00 views/
ls -R lib
database.rb       db_scheme.rb      db_status.yaml    fileutils.rb      greek-dict.txt        greekcase.rb      rankmanager.rb    wodb_el_v0.0.1.db

The database is located in lib/wodb_el_v0.0.1.db. All these files contain classes.

When I run tests in rankmanager.rb or database.rb by calling the classes by adding lines like:

Class TestClass
[code goes here]
end
x = TestClass.new
x.test_class_method

When I do that everything runs fine. When I remove the lines to perform the test (where I create the object and run the method) and require_relative in my application.rb, it erases the database instead of using it. The database is handled by the db_scheme.rb which is loaded by database.rb.

My db_scheme.rb is the gist.

Any idea why datamapper behaves like that?

ps. I load data to the database by running a manually a method from database.rb which creates the database.

Best Regards and thanks for your time in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:00:15+00:00Added an answer on June 16, 2026 at 1:00 pm

    In your db_scheme.rb you have:

    version = '0.0.1' # database version
    db = 'wodb_el_v' + version + '.db' #db location
    
    DataMapper.setup( :default, "sqlite3:///Users/atma/Dropbox/Programming/Projects/Local/HOWDB/lib/#{db}" )
    
    ...
    
    if File.exists?(db)
        DataMapper.auto_upgrade!
    else
        DataMapper.auto_migrate! # erases and creates the database. This needs run before any work is done with the database!
    end
    

    The line if File.exists?(db) checks to see if the file exists in the current working directory, i.e. the directory you start your program from. When you start Thin, that directory will be the parent directory, not the lib directory, so the file won’t be found and auto_migrate! will be run, erasing your data.

    You should make sure you always deal with the absolute path to your database file:

    version = '0.0.1' # database version
    db = File.expand_path('../wodb_el_v#{version}.db', __FILE__)
    
    DataMapper.setup(:default, "sqlite3:///#{db}" )
    
    if File.exists?(db) #db is now the absolute path
      # as before...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.