2016-01-21 17:06:09 +01:00
|
|
|
class CreateFranceConnectInformation < ActiveRecord::Migration
|
2018-03-06 13:44:29 +01:00
|
|
|
class User < ApplicationRecord
|
2016-01-21 17:06:09 +01:00
|
|
|
end
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class FranceConnectInformation < ApplicationRecord
|
2016-01-21 17:06:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def up
|
|
|
|
create_table :france_connect_informations do |t|
|
|
|
|
t.string :gender
|
|
|
|
t.string :given_name
|
|
|
|
t.string :family_name
|
|
|
|
t.date :birthdate
|
|
|
|
t.string :birthplace
|
|
|
|
t.string :france_connect_particulier_id
|
|
|
|
end
|
|
|
|
|
|
|
|
add_reference :france_connect_informations, :user, references: :users
|
|
|
|
|
|
|
|
User.all.each do |user|
|
2018-01-15 15:34:26 +01:00
|
|
|
FranceConnectInformation.create({
|
|
|
|
gender: user.gender,
|
|
|
|
given_name: user.given_name,
|
|
|
|
family_name: user.family_name,
|
|
|
|
birthdate: user.birthdate,
|
|
|
|
birthplace: user.birthplace,
|
|
|
|
france_connect_particulier_id: user.france_connect_particulier_id,
|
|
|
|
user_id: user.id
|
|
|
|
}) if user.france_connect_particulier_id.present?
|
2016-01-21 17:06:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
remove_column :users, :gender
|
|
|
|
remove_column :users, :given_name
|
|
|
|
remove_column :users, :family_name
|
|
|
|
remove_column :users, :birthdate
|
|
|
|
remove_column :users, :birthplace
|
|
|
|
remove_column :users, :france_connect_particulier_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
add_column :users, :gender, :string
|
|
|
|
add_column :users, :given_name, :string
|
|
|
|
add_column :users, :family_name, :string
|
|
|
|
add_column :users, :birthdate, :date
|
|
|
|
add_column :users, :birthplace, :string
|
|
|
|
add_column :users, :france_connect_particulier_id, :string
|
|
|
|
|
|
|
|
FranceConnectInformation.all.each do |fci|
|
2018-03-02 16:27:03 +01:00
|
|
|
User.find(fci.user_id).update({
|
2018-01-15 15:34:26 +01:00
|
|
|
gender: fci.gender,
|
|
|
|
given_name: fci.given_name,
|
|
|
|
family_name: fci.family_name,
|
|
|
|
birthdate: fci.birthdate,
|
|
|
|
birthplace: fci.birthplace,
|
|
|
|
france_connect_particulier_id: fci.france_connect_particulier_id
|
|
|
|
})
|
2016-01-21 17:06:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
drop_table :france_connect_informations
|
|
|
|
end
|
|
|
|
end
|