An unofficial, mostly Bitwarden-compatible API server written in Ruby (Sinatra and ActiveRecord)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove ActiveRecord migration tools and info

It's been almost 2 years since switching to AR, and the migration
script requires yaml_db which brings in all of Rails.

-235
-59
AR-MIGRATE.md
··· 1 - ## Rubywarden 2 - 3 - ### Migrating From `bitwarden-ruby` to Rubywarden and ActiveRecord 4 - 5 - If you've used this application before it switched to using ActiveRecord 6 - (when it was called `bitwarden-ruby`), you need to do the following steps to 7 - migrate the data and generate the new table structures. 8 - 9 - Even though the migration script will import to a new database file at a 10 - different path, it is probably best to create a backup yourself. 11 - You can also copy the `db/production.sqlite3` to your local machine and do the 12 - migration there. 13 - After a successful migration you'd have to copy the updated database file back 14 - to the production machine. 15 - 16 - First make sure you have the latest code: 17 - 18 - git pull 19 - 20 - Then checkout to a specific revision where the migration was made: 21 - 22 - git checkout 40044728d 23 - 24 - Run `bundle` to add some required libraries for the migration: 25 - 26 - bundle --with migrate 27 - 28 - Now you are ready to do the migration: 29 - 30 - bundle exec ruby tools/migrate_to_ar.rb -e production 31 - 32 - The `-e` switch allows you to select the correct database environment from 33 - `db/config.yml`. 34 - 35 - The migration script will: 36 - 37 - - dump the contents of the old database (most likely at 38 - `db/production.sqlite`) to a temporary YAML file 39 - - create the new database at `db/production/production.sqlite3` using 40 - ActiveRecord migrations 41 - - import the contents from the dump file 42 - - remove the dump file 43 - 44 - Now your data is completely migrated into a new database at the new recommended 45 - path, and the library will now use ActiveRecord to handle anything database 46 - related. 47 - 48 - It is recommended to follow the 49 - [initial installation instructions](https://github.com/jcs/rubywarden#manual-setup) 50 - to create a new, unprivileged user to own the new `db/production/` database 51 - and run the server. 52 - 53 - Lastly, update to the current code: 54 - 55 - git checkout master 56 - 57 - And then follow the 58 - [update instructions](https://github.com/jcs/rubywarden#updating) 59 - to bring your database up to date with the latest migrations.
-4
Gemfile
··· 30 30 gem 'rubeepass', '~> 3.3' 31 31 end 32 32 33 - group :migrate, optional: true do 34 - gem 'yaml_db' 35 - end 36 - 37 33 gem 'pry'
-79
Gemfile.lock
··· 1 1 GEM 2 2 remote: https://rubygems.org/ 3 3 specs: 4 - actioncable (5.1.7) 5 - actionpack (= 5.1.7) 6 - nio4r (~> 2.0) 7 - websocket-driver (~> 0.6.1) 8 - actionmailer (5.1.7) 9 - actionpack (= 5.1.7) 10 - actionview (= 5.1.7) 11 - activejob (= 5.1.7) 12 - mail (~> 2.5, >= 2.5.4) 13 - rails-dom-testing (~> 2.0) 14 - actionpack (5.1.7) 15 - actionview (= 5.1.7) 16 - activesupport (= 5.1.7) 17 - rack (~> 2.0) 18 - rack-test (>= 0.6.3) 19 - rails-dom-testing (~> 2.0) 20 - rails-html-sanitizer (~> 1.0, >= 1.0.2) 21 - actionview (5.1.7) 22 - activesupport (= 5.1.7) 23 - builder (~> 3.1) 24 - erubi (~> 1.4) 25 - rails-dom-testing (~> 2.0) 26 - rails-html-sanitizer (~> 1.0, >= 1.0.3) 27 - activejob (5.1.7) 28 - activesupport (= 5.1.7) 29 - globalid (>= 0.3.6) 30 4 activemodel (5.1.7) 31 5 activesupport (= 5.1.7) 32 6 activerecord (5.1.7) ··· 42 16 public_suffix (>= 2.0.2, < 5.0) 43 17 arel (8.0.0) 44 18 backports (3.16.1) 45 - builder (3.2.4) 46 19 chunky_png (1.3.11) 47 20 coderay (1.1.2) 48 21 concurrent-ruby (1.1.6) 49 - crass (1.0.6) 50 22 djinni (2.2.5) 51 23 fagin (~> 1.2, >= 1.2.2) 52 - erubi (1.9.0) 53 24 fagin (1.2.2) 54 - globalid (0.4.2) 55 - activesupport (>= 4.2.0) 56 25 hilighter (1.5.9) 57 26 i18n (1.8.2) 58 27 concurrent-ruby (~> 1.0) ··· 60 29 jsoncfg (1.2.11) 61 30 jwt (2.2.1) 62 31 kgio (2.11.3) 63 - loofah (2.4.0) 64 - crass (~> 1.0.2) 65 - nokogiri (>= 1.5.9) 66 - mail (2.7.1) 67 - mini_mime (>= 0.1.1) 68 32 method_source (0.9.2) 69 - mini_mime (1.0.2) 70 - mini_portile2 (2.4.0) 71 33 minitest (5.14.0) 72 34 multi_json (1.14.1) 73 35 mustermann (1.1.1) 74 36 ruby2_keywords (~> 0.0.1) 75 - nio4r (2.5.2) 76 - nokogiri (1.10.8) 77 - mini_portile2 (~> 2.4.0) 78 37 os (1.0.1) 79 38 pbkdf2-ruby (0.2.1) 80 39 pry (0.12.2) ··· 86 45 rack 87 46 rack-test (1.1.0) 88 47 rack (>= 1.0, < 3) 89 - rails (5.1.7) 90 - actioncable (= 5.1.7) 91 - actionmailer (= 5.1.7) 92 - actionpack (= 5.1.7) 93 - actionview (= 5.1.7) 94 - activejob (= 5.1.7) 95 - activemodel (= 5.1.7) 96 - activerecord (= 5.1.7) 97 - activesupport (= 5.1.7) 98 - bundler (>= 1.3.0) 99 - railties (= 5.1.7) 100 - sprockets-rails (>= 2.0.0) 101 - rails-dom-testing (2.0.3) 102 - activesupport (>= 4.2.0) 103 - nokogiri (>= 1.6) 104 - rails-html-sanitizer (1.3.0) 105 - loofah (~> 2.3) 106 - railties (5.1.7) 107 - actionpack (= 5.1.7) 108 - activesupport (= 5.1.7) 109 - method_source 110 - rake (>= 0.8.7) 111 - thor (>= 0.18.1, < 2.0) 112 48 raindrops (0.19.1) 113 49 rake (13.0.1) 114 50 rotp (5.1.0) ··· 143 79 rack-protection (= 2.0.8.1) 144 80 sinatra (= 2.0.8.1) 145 81 tilt (~> 2.0) 146 - sprockets (4.0.0) 147 - concurrent-ruby (~> 1.0) 148 - rack (> 1, < 3) 149 - sprockets-rails (3.2.1) 150 - actionpack (>= 4.0) 151 - activesupport (>= 4.0) 152 - sprockets (>= 3.0.0) 153 82 sqlite3 (1.4.2) 154 - thor (1.0.1) 155 83 thread_safe (0.3.6) 156 84 tilt (2.0.10) 157 85 twofish (1.0.8) ··· 160 88 unicorn (5.5.3) 161 89 kgio (~> 2.6) 162 90 raindrops (~> 0.7) 163 - websocket-driver (0.6.5) 164 - websocket-extensions (>= 0.1.0) 165 - websocket-extensions (0.1.4) 166 - yaml_db (0.7.0) 167 - rails (>= 3.0) 168 - rake (>= 0.8.7) 169 91 170 92 PLATFORMS 171 93 ruby ··· 188 110 sinatra-contrib (~> 2.0.0) 189 111 sqlite3 190 112 unicorn 191 - yaml_db 192 113 193 114 RUBY VERSION 194 115 ruby 2.4.2p198
-5
README.md
··· 99 99 100 100 ### Updating 101 101 102 - If you've previously used Rubywarden before July 30, 2018 when it was called 103 - `bitwarden-ruby`, when it did not use ActiveRecord, you should instead 104 - [migrate](AR-MIGRATE.md) 105 - your existing database. 106 - 107 102 To update your instance of Rubywarden, fetch the latest code: 108 103 109 104 cd /path/to/your/rubywarden
-88
tools/migrate_to_ar.rb
··· 1 - # see https://github.com/jcs/rubywarden/blob/master/AR-MIGRATE.md 2 - 3 - require "fileutils" 4 - require "getoptlong" 5 - require "tempfile" 6 - require "yaml_db" 7 - 8 - def usage 9 - puts "usage: #{$PROGRAM_NAME} -e development" 10 - exit 1 11 - end 12 - 13 - environment = nil 14 - begin 15 - GetoptLong.new( 16 - ['--environment', '-e', GetoptLong::REQUIRED_ARGUMENT] 17 - ).each do |opt, arg| 18 - case opt 19 - when '--environment' 20 - environment = arg 21 - end 22 - end 23 - rescue GetoptLong::InvalidOption 24 - usage 25 - end 26 - 27 - usage unless environment 28 - 29 - require File.realpath(File.dirname(__FILE__) + "/../lib/rubywarden.rb") 30 - 31 - ActiveRecord::Base.remove_connection 32 - 33 - dbconfig = YAML.load(File.read(File.realpath(__dir__ + "/../db/config.yml"))) 34 - 35 - # if a file exists at the new path, some kind of migration has already been 36 - # done so bail out 37 - newdb = dbconfig[environment]["database"] 38 - if File.exists?(newdb) 39 - raise "a file already exists at #{newdb}, has a migration already taken place?" 40 - end 41 - 42 - olddb = File.realpath(__dir__ + "/../db/production.sqlite3") 43 - if !olddb || !File.exists?(olddb) 44 - raise "no file at #{olddb} to migrate" 45 - end 46 - 47 - # point a temporary config at the old db path so we can dump it 48 - tmpconfig = dbconfig[environment].dup 49 - tmpconfig["database"] = olddb 50 - ActiveRecord::Base.establish_connection tmpconfig 51 - 52 - # select only tables for defined models 53 - class YamlDb::SerializationHelper::Dump 54 - def self.tables 55 - ObjectSpace.each_object(Class).select{|k| k < DBModel}.map{|k| k.table_name } 56 - end 57 - end 58 - 59 - dump_file = Tempfile.new("rubywarden-migrate") 60 - 61 - puts "dumping old database to #{dump_file.path}" 62 - YamlDb::SerializationHelper::Base.new(YamlDb::Helper).dump(dump_file.path) 63 - ActiveRecord::Base.remove_connection 64 - 65 - puts "creating new database at #{dbconfig[environment]["database"]}" 66 - system("rake", "db:migrate", "RUBYWARDEN_ENV=#{environment}") 67 - 68 - puts "importing old database dump" 69 - ActiveRecord::Base.establish_connection dbconfig[environment] 70 - YamlDb::SerializationHelper::Base.new(YamlDb::Helper).load(dump_file.path) 71 - 72 - puts "deleting dump file" 73 - dump_file.unlink 74 - 75 - # reset created_at / updated_at from seconds since epoch to actual datetime for ar magic 76 - DBModel.record_timestamps = false 77 - ObjectSpace.each_object(Class).select {|k| k < DBModel}.each do |k| 78 - k.all.each do |i| 79 - i.update created_at: Time.at(i.created_at), updated_at: Time.at(i.updated_at) 80 - end 81 - end 82 - DBModel.record_timestamps = true 83 - 84 - newdb = File.realpath(__dir__ + "/../" + dbconfig[environment]["database"]) 85 - puts "you may wish to delete the old database at #{newdb}" 86 - 87 - puts "you may also wish to create a new, unprivileged user to run the" 88 - puts "rubywarden server and own the db/production/ directory"