I am using Rails 5.2.2 and SQLCipher Version 3.2.0 (based on SQLite 3.8.6).
I have encrypted the SQLite database using sqlcipher but I am not able to load the rails application. The message is get is as follows:
SQLite3::NotADatabaseException: file is encrypted or is not a database: SELECT name FROM sqlite_master WHERE name <> 'sqlite_sequence' AND name = 'schema_migrations' AND type IN ('table')
I think that my issue lies in updating the file config/database.yml and specifying the password. I have tried specifying options like password, key, etc. but with no success.
I was wondering whether it is at all possible to use encrypted SQLite database in rails?
It's not a matter of which version of Ruby you are using, it's a matter of does there exist an adapter for the database you would like to use.
Rails tries to talk to all databases the same way, each database technology needs to provide an adapter to translate what Rails is asking for into the commands needed by that database technology to accomplish what Rails is asking for.
This configuration is done in the config/database.yml file, which might look something like the following (notice the adapter stanza):
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
There are many database adapters available, including SQLite, but I have not seen any for SQLCipher, you might have better luck searching than I did.
From what I have seen most Rails apps don't encrypt the entire database, but do however encrypt certain columns, for example storing some encrypted version of a password or access token.
Related
I have a rails app setup on a google cloud instance. I want to have the db in a SQL instance for the extra performance. But I cant see how to do this for a rails app.
I understand you create the SQL instance, start it, install mysql, on it but then how can I have the db and tables added? Creating them manually isn't going to be the solution because normally with rails apps you run rake db:create and rake db:migrate create the DB with tables and columns but this just makes a development.sqlite3 file not a mysql db..
I haven't deployed a rails app before so I think I'm missing something.
Here is my config/databast.yml file
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
mysql_settings: &mysql_settings
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: root
host: 130.211.71.150
database: dbname
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
I cant find out what needs to be done to have the db be created and tables and columns migrated into the mysql DB.
In your gem file you can put the sqlite gem under a development/test block and you can add the mysql gem in a production block.
In your database.yml file you can keep the development settings you have currently but then add another setting for production settings. Here you can include your mysql db settings (including the host and port of your SQL instance node)
When you launch your app, you can then launch it locally in development mode to use sqlite for development, but when deploying you can launch in production mode to utilize the mysql specific settings. From there you should be able to use db:create db:migrate etc to connect to that host and setup your Db.
Here is a nice article describes this process.
https://www.digitalocean.com/community/tutorials/scaling-ruby-on-rails-setting-up-a-dedicated-mysql-server-part-2
As a team, we chose to use mysql for local development as it more closely mimics what your prod environment will be like.
I want to use postgres db for my local and production environment both.
How should my gemfile look like for this case?
Should I completely remove sqlite and just put gem pg or the development and production environment is required with pg?
Please help.
In gemfile you only list the dependancies your application rely on. So, you don't have to remove sqlite from there, it really won't make any difference (but of corse it's better to remove it if you don't use it).
The place where you config your application which db to use is database.yml. You can find all the info here http://edgeguides.rubyonrails.org/configuring.html#configuring-a-database.
In short, you should add following to your database.yml:
development:
adapter: postgresql
database: blog_development
pool: 5
production:
adapter: postgresql
database: blog_production
pool: 5
I used to develop on SQLite3 and deploy on PostgreSQL. However, after this question I realised the importance of having the same database for development and production.
After many problems, I finally managed to install the PostgreSQL on my Mac OS X Lion 10.7.4. However, I am still facing some problems:
Using SQLite3 the databases' path is defined on the database.yml, which rails automatically creates within each new project.
Using PostgreSQL the database name is defined on the database.yml, which rails doesn't create automatically.
My question:
Shall I create a new database for each new project or shall I change the database.yml to include the same database for all projects?
I saw people saying that each user in a computer should have one database, when using PostgreSQL.
Well, if the best practice is to create one database for each project (which I hope so)...
There is any way to configure rails to create the new database automatically within each new project?
Creating a DB is mostly one-time operation, so it's not a big deal to create it once for a project. A casual Postgresql admin can use pgAdmin graphical tool.
If you use Postgresql for development, you need to create database by your self.
But you can initialize you project for Postgresql.
rails new my_project -d postgresql
Have a good day.
Benjamin.
Problem solved:
I have followed this tutorial and I could finally solve the problem.
I have created a new user for my postgreSQL called user1 without any password, so each time I create a new project I just need to change the database.yml for the below:
development:
adapter: postgresql
encoding: unicode
database: newproject_development
pool: 5
username: user1 #I am changing this line
password:
test:
adapter: postgresql
encoding: unicode
database: newproject_test
pool: 5
username: user1 #I am changing this line
password:
production:
adapter: postgresql
encoding: unicode
database: newproject_production
pool: 5
username: user1 #I am changing this line
password:
As the the user1 doen't have any password, now I can just create the tables using the Rails rake.
rake db:create:all
I am new in ror developement..i was working on a LIVE server...I just uploaded a file through sftp...after 1 day server suddenly stopped working...You can see the error message from here
it shows
There appears to be a database problem.
Your config/database.yml may not be written correctly. Please check it and fix any errors.
Your database schema may be out of date or nonexistant. Please run rake db:migrate to ensure that the database schema is up-to-date.
The database server may not be running. Please check whether it's running, and start it if it isn't.
Looking at the error page you seem to be using Rails 2.3?
At a guess you have a MySQL database not an SQLite running. You should have the user name and password for the database around somewhere (replace the relevant fields in the 3 sections with them).
Change the database names to reflect your database names.
The server admins might have set a specific socket for MySQL in which case replace the '/tmp/mysql.sock' with the socket number.
Check your Gems to see if the MySQL adapter is installed (you appear to be using Rails 2.3 so try gem list on the terminal for your server - make sure that you are in the root directory for the app).
If the MySQL gem is missing use gem install to install it (this will depend on what your hosting provider allows).
The following links are pretty old - targetted towards Rails 2 which you appear to be using.
http://www.ruby-forum.com/topic/139710
http://forums.mysql.com/read.php?116,353922,359544
database.yml
development:
adapter: mysql
encoding: utf8
database: temp_development
username: root
password:
socket: /tmp/mysql.sock
# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
database: temp_test
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
database: temp_production
username: root
password:
socket: /tmp/mysql.sock
I am using instant rails which makes use of SQLite and I am unable to connect to the database. I have been using a tutorial that uses MySQL and I have been unable to find instructions for SQLite. Any suggestions?
You could install sqlite.
Or, assuming you have mysql installed, you could change your config/database.yml file to use mysql instead of sqlite.
(From using rails -d mysql testapp)
development:
adapter: mysql
encoding: utf8
reconnect: false
database: awesome_development
pool: 5
username: root
password:
host: localhost
Update
To use sqlite3, you need the sqlite gem and to set up your rails database.yml to use it. The default config rails generates uses sqlite and looks like this
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
to install, here are some good looking instructions