Commit fa2c4a37 authored by Nina's avatar Nina

Upgrade ActiveRecord

* Specify ActiveRecord version in each migration
* Adjust migrations spec to the new AcitveRecord::Migrator API
parent 2ea13bda
Pipeline #22084 passed with stages
in 6 minutes and 41 seconds
class CreateLists < ActiveRecord::Migration
class CreateLists < ActiveRecord::Migration[5.2]
def up
if ! table_exists?(:lists)
create_table :lists do |t|
......
class CreateSubscriptions < ActiveRecord::Migration
class CreateSubscriptions < ActiveRecord::Migration[5.2]
def up
if ! table_exists?(:subscriptions)
create_table :subscriptions do |t|
......
class AddLanguageToLists < ActiveRecord::Migration
class AddLanguageToLists < ActiveRecord::Migration[5.2]
def up
if ! column_exists?(:lists, :language)
add_column :lists, :language, :string, default: 'en'
......
class ChangeKeywordsAdminOnlyDefaults < ActiveRecord::Migration
class ChangeKeywordsAdminOnlyDefaults < ActiveRecord::Migration[5.2]
def up
change_column_default :lists, :keywords_admin_only, "[\"subscribe\", \"unsubscribe\", \"delete-key\"]"
end
......
class AddForwardAllIncomingToAdmins < ActiveRecord::Migration
class AddForwardAllIncomingToAdmins < ActiveRecord::Migration[5.2]
def up
if ! column_exists?(:lists, :forward_all_incoming_to_admins)
add_column :lists, :forward_all_incoming_to_admins, :boolean, default: false
......
class ChangeSendEncryptedOnlyDefault < ActiveRecord::Migration
class ChangeSendEncryptedOnlyDefault < ActiveRecord::Migration[5.2]
def up
change_column_default :lists, :send_encrypted_only, true
end
......
class AddLogfilesToKeepToLists < ActiveRecord::Migration
class AddLogfilesToKeepToLists < ActiveRecord::Migration[5.2]
def up
if ! column_exists?(:lists, :logfiles_to_keep)
add_column :lists, :logfiles_to_keep, :integer, default: 2
......
class RenameDeliveryDisabledToDeliveryEnabledAndChangeDefault < ActiveRecord::Migration
class RenameDeliveryDisabledToDeliveryEnabledAndChangeDefault < ActiveRecord::Migration[5.2]
def up
if column_exists?(:subscriptions, :delivery_disabled)
rename_column :subscriptions, :delivery_disabled, :delivery_enabled
......
class StripGpgPassphrase < ActiveRecord::Migration
class StripGpgPassphrase < ActiveRecord::Migration[5.2]
def up
if column_exists?(:lists, :gpg_passphrase)
remove_column :lists, :gpg_passphrase
......
class RemoveDefaultMime < ActiveRecord::Migration
class RemoveDefaultMime < ActiveRecord::Migration[5.2]
def up
remove_column :lists, :default_mime
end
......
class FixHeadersToMetaDefaults < ActiveRecord::Migration
class FixHeadersToMetaDefaults < ActiveRecord::Migration[5.2]
def up
change_column_default :lists, :headers_to_meta, '["from", "to", "date", "cc"]'
end
......
class AddInternalFooterToList < ActiveRecord::Migration
class AddInternalFooterToList < ActiveRecord::Migration[5.2]
def up
if ! column_exists?(:lists, :internal_footer)
add_column :lists, :internal_footer, :text, default: ''
......
class AddSigEncToHeadersToMetaDefaults < ActiveRecord::Migration
class AddSigEncToHeadersToMetaDefaults < ActiveRecord::Migration[5.2]
def up
change_column_default :lists, :headers_to_meta, '["from", "to", "cc", "date", "sig", "enc"]'
list_klass = create_list_klass
......
class CreateAccounts < ActiveRecord::Migration
class CreateAccounts < ActiveRecord::Migration[5.2]
def up
create_table :accounts do |t|
t.string :email, null: false
......
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
......@@ -11,60 +10,58 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180202183800) do
ActiveRecord::Schema.define(version: 2018_02_02_183800) do
create_table "accounts", force: :cascade do |t|
t.string "email", null: false
t.string "password_digest", null: false
t.boolean "api_superadmin", default: false, null: false
t.string "email", null: false
t.string "password_digest", null: false
t.boolean "api_superadmin", default: false, null: false
t.index ["email"], name: "index_accounts_on_email", unique: true
end
add_index "accounts", ["email"], name: "index_accounts_on_email", unique: true
create_table "lists", force: :cascade do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "email", limit: 255
t.string "fingerprint", limit: 255
t.string "log_level", limit: 255, default: "warn"
t.string "subject_prefix", limit: 255, default: ""
t.string "subject_prefix_in", limit: 255, default: ""
t.string "subject_prefix_out", limit: 255, default: ""
t.string "openpgp_header_preference", limit: 255, default: "signencrypt"
t.text "public_footer", default: ""
t.text "headers_to_meta", default: "[\"from\", \"to\", \"cc\", \"date\", \"sig\", \"enc\"]"
t.text "bounces_drop_on_headers", default: "{\"x-spam-flag\":\"yes\"}"
t.text "keywords_admin_only", default: "[\"subscribe\", \"unsubscribe\", \"delete-key\"]"
t.text "keywords_admin_notify", default: "[\"add-key\"]"
t.boolean "send_encrypted_only", default: true
t.boolean "receive_encrypted_only", default: false
t.boolean "receive_signed_only", default: false
t.boolean "receive_authenticated_only", default: false
t.boolean "receive_from_subscribed_emailaddresses_only", default: false
t.boolean "receive_admin_only", default: false
t.boolean "keep_msgid", default: true
t.boolean "bounces_drop_all", default: false
t.boolean "bounces_notify_admins", default: true
t.boolean "include_list_headers", default: true
t.boolean "include_openpgp_header", default: true
t.integer "max_message_size_kb", default: 10240
t.string "language", limit: 255, default: "en"
t.boolean "forward_all_incoming_to_admins", default: false
t.integer "logfiles_to_keep", default: 2
t.text "internal_footer", default: ""
t.string "email", limit: 255
t.string "fingerprint", limit: 255
t.string "log_level", limit: 255, default: "warn"
t.string "subject_prefix", limit: 255, default: ""
t.string "subject_prefix_in", limit: 255, default: ""
t.string "subject_prefix_out", limit: 255, default: ""
t.string "openpgp_header_preference", limit: 255, default: "signencrypt"
t.text "public_footer", default: ""
t.text "headers_to_meta", default: "[\"from\", \"to\", \"cc\", \"date\", \"sig\", \"enc\"]"
t.text "bounces_drop_on_headers", default: "{\"x-spam-flag\":\"yes\"}"
t.text "keywords_admin_only", default: "[\"subscribe\", \"unsubscribe\", \"delete-key\"]"
t.text "keywords_admin_notify", default: "[\"add-key\"]"
t.boolean "send_encrypted_only", default: true
t.boolean "receive_encrypted_only", default: false
t.boolean "receive_signed_only", default: false
t.boolean "receive_authenticated_only", default: false
t.boolean "receive_from_subscribed_emailaddresses_only", default: false
t.boolean "receive_admin_only", default: false
t.boolean "keep_msgid", default: true
t.boolean "bounces_drop_all", default: false
t.boolean "bounces_notify_admins", default: true
t.boolean "include_list_headers", default: true
t.boolean "include_openpgp_header", default: true
t.integer "max_message_size_kb", default: 10240
t.string "language", limit: 255, default: "en"
t.boolean "forward_all_incoming_to_admins", default: false
t.integer "logfiles_to_keep", default: 2
t.text "internal_footer", default: ""
end
create_table "subscriptions", force: :cascade do |t|
t.integer "list_id"
t.string "email", limit: 255
t.string "fingerprint", limit: 255
t.boolean "admin", default: false
t.boolean "delivery_enabled", default: true
t.integer "list_id"
t.string "email", limit: 255
t.string "fingerprint", limit: 255
t.boolean "admin", default: false
t.boolean "delivery_enabled", default: true
t.datetime "created_at"
t.datetime "updated_at"
t.index ["email", "list_id"], name: "index_subscriptions_on_email_and_list_id", unique: true
t.index ["list_id"], name: "index_subscriptions_on_list_id"
end
add_index "subscriptions", ["email", "list_id"], name: "index_subscriptions_on_email_and_list_id", unique: true
add_index "subscriptions", ["list_id"], name: "index_subscriptions_on_list_id"
end
......@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'gpgme', '~> 2.0', '>= 2.0.13' # Explicitly include to force a version.
s.add_runtime_dependency 'mail', '~> 2.6.0'
s.add_runtime_dependency 'mail-gpg', '~> 0.3', '>= 0.3.3'
s.add_runtime_dependency 'activerecord', '~> 4.2'
s.add_runtime_dependency 'activerecord', '~> 5.2'
s.add_runtime_dependency 'bcrypt-ruby', '~> 3.1.2'
s.add_runtime_dependency 'rake', '>= 10.5.0'
s.add_runtime_dependency 'sqlite3', '~> 1'
......
require 'spec_helper'
describe 'AddSigEncToHeadersToMetaDefaults' do
let(:migrations_paths) { 'db/migrate' }
let(:migrations) { ActiveRecord::Migration[5.2].new.migration_context.migrations }
let(:migration_under_test) { 20180110203100 }
let(:previous_migration) { 20170713215059 }
after(:each) do
ActiveRecord::Migrator.migrate(migrations_paths)
ActiveRecord::Migrator.new(:up, migrations).migrate
end
describe 'up' do
it 'sets the column defaults' do
ActiveRecord::Migrator.migrate(migrations_paths, previous_migration)
ActiveRecord::Migrator.new(:down, migrations, previous_migration).migrate
list_klass = create_list_klass
list_klass.reset_column_information
ActiveRecord::Migrator.migrate(migrations_paths, migration_under_test)
ActiveRecord::Migrator.new(:up, migrations, migration_under_test).migrate
list_klass.reset_column_information
expect(list_klass.column_defaults['headers_to_meta']).to eql(['from', 'to', 'cc', 'date', 'sig', 'enc'])
end
it 'adds sig and enc to headers_to_meta for lists wihtout the attributes' do
ActiveRecord::Migrator.migrate(migrations_paths, previous_migration)
ActiveRecord::Migrator.new(:down, migrations, previous_migration).migrate
list_klass = create_list_klass
list = create(:list, headers_to_meta: list_klass.column_defaults['headers_to_meta'])
expect(list.headers_to_meta).not_to include('enc', 'sig')
ActiveRecord::Migrator.migrate(migrations_paths, migration_under_test)
ActiveRecord::Migrator.new(:up, migrations, migration_under_test).migrate
list_klass.reset_column_information
list.reload
......@@ -37,13 +37,13 @@ describe 'AddSigEncToHeadersToMetaDefaults' do
it 'does not add sig and enc to headers to meta if the attributes already exist' do
headers_to_meta_including_sig_and_enc = ['from', 'to', 'cc', 'date', 'sig', 'enc']
ActiveRecord::Migrator.migrate(migrations_paths, previous_migration)
ActiveRecord::Migrator.new(:down, migrations, previous_migration).migrate
list_klass = create_list_klass
list = create(:list, headers_to_meta: headers_to_meta_including_sig_and_enc)
expect(list.headers_to_meta).to eql headers_to_meta_including_sig_and_enc
ActiveRecord::Migrator.migrate(migrations_paths, migration_under_test)
ActiveRecord::Migrator.new(:up, migrations, migration_under_test).migrate
list_klass.reset_column_information
list.reload
......@@ -53,25 +53,25 @@ describe 'AddSigEncToHeadersToMetaDefaults' do
describe 'down' do
it 'sets the column defaults' do
ActiveRecord::Migrator.migrate(migrations_paths, migration_under_test)
ActiveRecord::Migrator.new(:up, migrations, migration_under_test).migrate
list_klass = create_list_klass
list_klass.reset_column_information
ActiveRecord::Migrator.migrate(migrations_paths, previous_migration)
ActiveRecord::Migrator.new(:down, migrations, previous_migration).migrate
list_klass.reset_column_information
expect(list_klass.column_defaults['headers_to_meta']).to eql(['from', 'to', 'cc', 'date'])
end
it 'removes sig and enc from headers_to_meta from existing lists' do
ActiveRecord::Migrator.migrate(migrations_paths, migration_under_test)
ActiveRecord::Migrator.new(:up, migrations, migration_under_test).migrate
list_klass = create_list_klass
list_klass.reset_column_information
list = create(:list, headers_to_meta: list_klass.column_defaults['headers_to_meta'])
expect(list.headers_to_meta).to include('enc', 'sig')
ActiveRecord::Migrator.migrate(migrations_paths, previous_migration)
ActiveRecord::Migrator.new(:down, migrations, previous_migration).migrate
list_klass.reset_column_information
list.reload
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment