Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty my Sqlite3 database in RoR

I am working on a Ruby on Rails 3 web application using sqlite3. I have been testing my application on-the-fly creating and destroying things in the Database, sometimes through the new and edit actions and sometimes through the Rails console.

I am interested in emptying my Database totally and having only the empty tables left. How can I achieve this? I am working with a team so I am interested in two answers: 1) How do I empty the Database only by me? 2) How can I (if possible empty) it by the others (some of which are not using sqlite3 but MySql)? (we are all working on an the same project through a SVN repository)

like image 261
Nachshon Schwartz Avatar asked Jan 24 '11 10:01

Nachshon Schwartz


People also ask

How do I clear a SQLite database?

SQLite stores its databases as a normal file within the computer's file system, so creating and dropping databases is not really applicable. If you need to completely remove a database, you will need to delete the database file from the file system. Then you can navigate to the file in the file system and delete it.

How do I reset a Rails database?

db:reset: Resets your database using your migrations for the current environment. It does this by running the db:drop , db:create , db:migrate tasks. db:rollback: Rolls the schema back to the previous version, undoing the migration that you just ran. If you want to undo previous n migrations, pass STEP=n to this task.

Where are sqlite3 databases stored?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.


1 Answers

To reset your database, you can run:

rake db:schema:load

Which will recreate your database from your schema.rb file (maintained by your migrations). This will additionally protect you from migrations that may later fail due to code changes.

Your dev database should be distinct to your environment - if you need certain data, add it to your seed.rb file. Don't share a dev database, as you'll quickly get into situations where other changes make your version incompatible.

like image 101
Codebeef Avatar answered Sep 24 '22 14:09

Codebeef