···37373838Run `bundle install` at least once.
39394040+In order to create the database and the required tables run:
4141+4242+ env RACK_ENV=production bundle exec rake db:migrate
4343+4044To run via Rack on port 4567:
41454246 env RACK_ENV=production bundle exec rackup -p 4567 config.ru
···6367```
6468env RACK_ENV=production bundle exec ruby tools/change_master_password.rb -u you@example.com
6569```
7070+7171+### Migrating to ActiveRecord
7272+7373+If you've used this library before it switched to using ActiveRecord, you need to do the following steps to migrate the data and generate the new table structures. Even though the migration script will create a backup of your database, it is probably best to create a backup yourself. You can also copy the ```db/production.sqlite3``` to your local machine and do the migration there. After a successful migration you'd have to copy the updated database file back to the production machine.
7474+7575+First make sure you have the latest code:
7676+7777+ git pull
7878+7979+Afterwards you need to run bundle to add some required libraries for the migration
8080+8181+ bundle --with migrate
8282+8383+Now you are ready to do the migration
8484+8585+ ruby tools/migrate_to_ar.rb -e production
8686+8787+The -e switch allows you to select the correct database environment from db/config.yml. The migration script will:#
8888+8989+ * dump the contents of the database to a YAML file
9090+ * rename the original database file to ```production.sqlite3.#{Time.now.to_i}```
9191+ * create the database using ActiveRecord migrations
9292+ * load the contents from the dump file
9393+ * remove the dump file
9494+9595+Now your data is completely migrated and the library will now use ActiveRecord to handle anything database related :-)
66966797### 1Password Conversion
6898···127157128158### Keepass Conversion
129159130130-In order to use the Keepass converter, you will need to install the necessary
160160+In order to use the Keepass converter, you will need to install the necessary
131161dependency, using `bundle install --with keepass`.
132162133163There is no need to export your Keepass-database - you can use it as is.
+7
Rakefile
···11require "rake/testtask"
22+require "sinatra/activerecord/rake"
2334Rake::TestTask.new do |t|
45 t.pattern = "spec/*_spec.rb"
56end
77+88+namespace :db do
99+ task :load_config do
1010+ require "./app"
1111+ end
1212+end
···11+class SetDefaultValueForFavorite < ActiveRecord::Migration[5.1]
22+ class Cipher < ActiveRecord::Base; end
33+ def change
44+ change_column_default :ciphers, :favorite, false
55+ change_column_null(:ciphers, :favorite, false, false)
66+ end
77+end
+5
lib/app.rb
···1414# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515#
16161717+require 'sinatra/activerecord'
1818+1719require_relative 'helpers/request_helpers'
18201921require_relative 'routes/api'
···2325module BitwardenRuby
2426 class App < Sinatra::Base
2527 register Sinatra::Namespace
2828+ register Sinatra::ActiveRecordExtension
26292730 set :root, File.dirname(__FILE__)
3131+ set :database_file, "../db/config.yml"
3232+2833 configure do
2934 enable :logging
3035 end