Backup and restore – account migration

I thought about it some time ago but unfortunately no I don’t have the rights to create them.

About Backup and restore – account migration - #179 by goob well it still is prominent but probably better than what we proposed. I still don’t know how to present it, or if that’s really needed… I think I will focus on the UI in the settings at the moment.

Currently I am out of office. May be back later this day.
I do not know exactly what the task does if uploading a profile. (In terms of setting password or migrating personal profile data)
There is currently not task to import photos.

So, I tried locally the import of my very old profile from diasp.org. The validation went well, but the actual migration failed, is that just because I’m running on localhost @supertux88?

https://gist.githubusercontent.com/Flaburgan/beb704a006ae1a299f4e1caf11bd70c2/raw/e1a7729bd002dbe42171172a0a830f279151fa91/Import%20from%20diasp.org

Actually if I launch it again it works, so I don’t know if the initial cert errors were only about some old pods…

I actually hit an interesting case:

Do you really want to execute the archive import? Note: this is irreversible! [y/N]: y
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE "users"."username" = $1 LIMIT $2  [["username", "teest"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Exists (0.4ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "flaburgan@XXXX"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE "users"."username" = $1 LIMIT $2  [["username", "teest"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE (id != NULL AND email = NULL) LIMIT $1  [["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   Person Exists (0.3ms)  SELECT  1 AS one FROM "people" WHERE "people"."diaspora_handle" = $1 LIMIT $2  [["diaspora_handle", "teest@localhost:3000"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:    (0.1ms)  BEGIN
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Exists (0.3ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "flaburgan@XXXX"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE "users"."username" = $1 LIMIT $2  [["username", "teest"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE (id != NULL AND email = NULL) LIMIT $1  [["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:   Person Exists (0.2ms)  SELECT  1 AS one FROM "people" WHERE "people"."diaspora_handle" = $1 LIMIT $2  [["diaspora_handle", "teest@localhost:3000"], ["LIMIT", 1]]
[2021-09-08T21:19:53] DEBUG PID-17442 TID-62280 ActiveRecord::Base:    (0.2ms)  ROLLBACK
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Email is already taken., Person can't be blank
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/validations.rb:80:in `raise_validation_error'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/validations.rb:52:in `save!'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/transactions.rb:315:in `block in save!'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/transactions.rb:387:in `block in with_transaction_returning_status'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `block in transaction'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `synchronize'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:267:in `transaction'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/transactions.rb:212:in `transaction'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/transactions.rb:385:in `with_transaction_returning_status'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/transactions.rb:315:in `save!'
/var/lib/gems/2.7.0/gems/activerecord-5.2.6/lib/active_record/suppressor.rb:48:in `save!'
/home/fla/diaspora/diaspora/lib/archive_importer.rb:40:in `create_user'
/home/fla/diaspora/diaspora/app/services/migration_service.rb:51:in `find_or_create_user'
/home/fla/diaspora/diaspora/app/services/migration_service.rb:22:in `perform!'
/home/fla/diaspora/diaspora/lib/tasks/accounts.rake:22:in `block (2 levels) in <top (required)>'
Tasks: TOP => accounts:migration
(See full trace by running task with --trace)

So if another user that the one who is imported as the same e-mail than in the archive, the import fails. Is that what we want? I could imagine a valid case where a user has two accounts in a pod, wants to merge a third one in one account, but the email in the archive is the same than the email of the second account. I know, few chances that this would happen but ?

1 Like

I also have some errors like this in the logs:

[2021-09-08T23:51:53] ERROR PID-31334 TID-62280 DiasporaFederation::Federation::Receiver: failed to receive public message: DiasporaFederation::Salmon::InvalidEnvelope: DiasporaFederation::Salmon::InvalidEnvelope

But I guess those messages are just ignored.

The old code tries to create a user every time, but needs to do a “find_or_create”.
Then, not all attributes are set correctly.
Can you try this patch?

Index: app/models/user.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/app/models/user.rb b/app/models/user.rb
--- a/app/models/user.rb	(revision d88529ccd10adbfb201423b0183f6c8e6f3bfa92)
+++ b/app/models/user.rb	(date 1631138799981)
@@ -404,12 +404,20 @@
   end
 
   ###Helpers############
-  def self.build(opts = {})
+  def self.build(opts={})
     u = User.new(opts.except(:person, :id))
     u.setup(opts)
     u
   end
 
+  def self.find_or_build(opts={})
+    user = User.find_or_create_by(username: opts[:username], email: opts[:email])
+    user.password ||= opts[:password]
+    user.password_confirmation ||= opts[:password]
+    user.setup(opts)
+    user
+  end
+
   def setup(opts)
     self.username = opts[:username]
     self.email = opts[:email]
@@ -417,6 +425,10 @@
     self.language ||= I18n.locale.to_s
     self.color_theme = opts[:color_theme]
     self.color_theme ||= AppConfig.settings.default_color_theme
+    self.strip_exif &&= opts[:strip_exif]
+    self.show_community_spotlight_in_stream = opts[:show_community_spotlight_in_stream]
+    self.auto_follow_back ||= opts[:auto_follow_back]
+    self.getting_started = false
     self.valid?
     errors = self.errors
     errors.delete :person
Index: spec/lib/archive_importer_spec.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/spec/lib/archive_importer_spec.rb b/spec/lib/archive_importer_spec.rb
--- a/spec/lib/archive_importer_spec.rb	(revision d88529ccd10adbfb201423b0183f6c8e6f3bfa92)
+++ b/spec/lib/archive_importer_spec.rb	(date 1631137969039)
@@ -147,7 +147,6 @@
       expect {
         archive_importer.create_user(username: "new_name", password: "123456")
       }.to change(User, :count).by(1)
-
       expect(archive_importer.user.email).to eq("user@example.com")
       expect(archive_importer.user.strip_exif).to eq(false)
       expect(archive_importer.user.show_community_spotlight_in_stream).to eq(false)
Index: lib/archive_importer.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/archive_importer.rb b/lib/archive_importer.rb
--- a/lib/archive_importer.rb	(revision d88529ccd10adbfb201423b0183f6c8e6f3bfa92)
+++ b/lib/archive_importer.rb	(date 1631136648126)
@@ -36,7 +36,7 @@
         profile_attributes: profile_attributes
       }
     )
-    self.user = User.build(data)
+    self.user = User.find_or_build(data)
     user.save!
   end
 

What do you mean by “old code”? I m in your upload_migration_files branch and I do have a find_or_create (migration_service.rb line 49, called line 22)

Maybe we should have those discussions on github, I’ll post my findings there now.

This is just a method name -
It calls

  • archive_importer.create_user(username: new_user_name, password: SecureRandom.hex)

and in Archive_user:39 a ‘build’ method, where a user is created every time.

One question that has just occurred to me:

Can the migration feature as currently constituted cope with a second import from the same account? I can imagine this happening in the following scenario.

  • Pod A goes down and is down for a while. I decide to open a new account on Pod B, because it looks as though Pod A is dead.
  • I open an account on Pod B and import a back-up taken a month before Pod A went down, because that’s better than nothing.
  • Later, Pod A goes online once again. Great! I can now migrate my account with all the up-to-date information to Pod B.

When I do this, will it:
a) fail with an error;
b) duplicate the content that was part of my earlier import;
c) recognise a previously imported account from the key and refuse to proceed with the migration;
d) recognise previously imported content and correctly skip that content?

1 Like

I would say it still works but not sure.

I’m leaving this evening for the whole week-end, I’ll be back only on Sunday evening. I started to post messages to explain users of Framasphere what is going on and some of them are willing to be beta-testers of the migration. I will do that with the rake task once we feel we’re ready, maybe beginning of next week? @tclaus could you add the photo import to the rake task?
@supertux88 @jhass @comradesenya I don’t want to put pressure on you, but if you have time to review part of Thorsten work, it would be really, really cool. Framasphère is closing in less than a month, so time is running out.

I don’t know this.
A Close message is send out to your old pod. This signings are repeated several times for some days (weeks?) So if your old pod comes back, chances are high that it will receive the close-message.

Maybe Supertux88 knows more?

Thank you very much for improving the rake task @tclaus ! I’m going to have a look at it this evening.
Could you please put that code in a separated branch than your work on the UI, so that once ready I can pull it in my pod without actually exposing the feature to the users?
Also, as you now have a lot of pull requests (which is a great thing), could you please number them in the title so we can easily now which one is based on what?

The “upload_migration_files” - branch now contains a (sorted) list of everything what is needed to complete the migration job.

  • the fixing import Issues PR
  • Comnpressed file handling
  • the UI / Rake Stuff
  • the latest ‘send message back…’ #8288

It does not contain the new welcome page

On immediately action, you might do a
$: git reset --hard upstream/develop – app/views/users/_edit.haml

To reset the user visible UI part.

@tclaus, I’ve just created Github tickets for the various issues I noticed. I’m sorry it has taken me so long to do this.

@denschub @supertux88 @jhass, would one of you be happy to create a label for migration in Github? It would be really useful to hold all of these issues and PRs together.

(One for gems or dependencies could also be useful, unless that’s covered by upstream).

I added “:jigsaw: dependencies” and “:truck: migration”.

(I know you’re not a huge fan of emojis, but lots of the other labels have emojis, and I’ve learned to like them over the years in many projects. :))

2 Likes

Thanks a lot. It’s only in communication that I don’t like emoji. I actually find them quite cute and funny in the Github labels. I like your latest choices!

@tclaus, I’ve added the new migration label to all the migration-related issues I could find. Let me know if I’ve missed any.

1 Like