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.
我正在使用sqlite3开发Ruby on Rails 3 web应用程序。我一直在动态地测试我的应用程序在数据库中创建和销毁东西,有时通过新的和编辑操作,有时通过Rails控制台。
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)
我对清空我的数据库感兴趣,只剩下空的桌子了。我如何做到这一点?我和一个团队一起工作,所以我对两个问题很感兴趣:1)如何只靠我清空数据库?2)我如何(如果可能的话)把它空给其他人(有些人不使用sqlite3,而是使用MySql)?(我们都在通过SVN存储库处理同一个项目)
4 个解决方案
#1
18
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.
它将从模式中重新创建数据库。rb文件(由您的迁移维护)。这还将保护您避免由于代码更改而导致的迁移。
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.
您的开发数据库应该与您的环境不同——如果您需要某些数据,请将其添加到您的种子中。rb文件。不要共享开发数据库,因为您将很快陷入其他更改导致版本不兼容的情况。
#2
2
Download sqlitebrower here http://sqlitebrowser.org/
在这里下载sqlitebrower http://sqlitebrowser.org/
Install it, run it, click open database (top left) to locationOfYourRailsApp/db/development.sqlite3
安装它,运行它,点击打开数据库(左上方)到locationOfYourRailsApp/db/development.sqlite3
Then switch to Browse data tab, there you can delete or add data.
然后切换到Browse data选项卡,在那里您可以删除或添加数据。
#3
0
As far as I know there is no USER GRANT management in sqlite so it is difficult to control access.
据我所知,sqlite中没有用户授权管理,所以很难控制访问。
You only can protect the database by file access.
您只能通过文件访问来保护数据库。
If you want to use an empty database for test purpose. Generate it once and copy the file somewhere. and use a copy of this file just before testing.
如果您想使用一个空的数据库进行测试。生成它一次并将文件复制到某处。并在测试前使用该文件的副本。
#4
0
I found that by deleting the deployment.sqlite3
file from the db
folder and inserting the command rake db:migrate
in the command line, it solves the problem for all of my team working on sqlite3.
我发现通过删除部署。来自db文件夹的sqlite3文件,并插入命令rake db: migration in the command line,它解决了所有处理sqlite3的团队的问题。
#1
18
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.
它将从模式中重新创建数据库。rb文件(由您的迁移维护)。这还将保护您避免由于代码更改而导致的迁移。
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.
您的开发数据库应该与您的环境不同——如果您需要某些数据,请将其添加到您的种子中。rb文件。不要共享开发数据库,因为您将很快陷入其他更改导致版本不兼容的情况。
#2
2
Download sqlitebrower here http://sqlitebrowser.org/
在这里下载sqlitebrower http://sqlitebrowser.org/
Install it, run it, click open database (top left) to locationOfYourRailsApp/db/development.sqlite3
安装它,运行它,点击打开数据库(左上方)到locationOfYourRailsApp/db/development.sqlite3
Then switch to Browse data tab, there you can delete or add data.
然后切换到Browse data选项卡,在那里您可以删除或添加数据。
#3
0
As far as I know there is no USER GRANT management in sqlite so it is difficult to control access.
据我所知,sqlite中没有用户授权管理,所以很难控制访问。
You only can protect the database by file access.
您只能通过文件访问来保护数据库。
If you want to use an empty database for test purpose. Generate it once and copy the file somewhere. and use a copy of this file just before testing.
如果您想使用一个空的数据库进行测试。生成它一次并将文件复制到某处。并在测试前使用该文件的副本。
#4
0
I found that by deleting the deployment.sqlite3
file from the db
folder and inserting the command rake db:migrate
in the command line, it solves the problem for all of my team working on sqlite3.
我发现通过删除部署。来自db文件夹的sqlite3文件,并插入命令rake db: migration in the command line,它解决了所有处理sqlite3的团队的问题。