Safe To Update from Version 2 to Version 3?

I was previously on version v2.5.2.2 (self-hosted).

I downloaded v3.3.3, copied over the latest zip and then ran https://invoices.mysite.com/update.

https://invoices.mysite.com/update presented me with an options screen which I was asked to fill up username, smtp etc - was feeling uneasy at this point since they should be already present in my existing database.

After submit, screen said update was successful and I could login into the new v3.3.3 but my database is now empty i.e. all my invoices, payments, everything is gone!

I restored my backup and am now back to v2.5.2.2.

So I would like to ask if there is an official upgrade path from v2 to v3 where my old data can be properly migrated? Have I missed any important step?

Were you using the original .env file, if you copied over the zip it should be there.

You shouldn’t see the setup screen unless the app can no longer connect to the database.

Thank you for your reply.

My way of “copying over the latest files” was actually renaming the existing ninja folder to “ninja-2.5.2.2” and then renaming the latest downloaded folder (with v3.3.3) to “ninja”.

Thus there is no original .env file only .env.example in the new folder. I mistakenly believed that by filling up and submitting the form, a new .env file (along with any new parameters that may come from new version) will be generated based on existing data in my database.

So am I correct to say I should have copied over my old .env file to my latest ninja folder?

Yes, that’s correct.

http://docs.invoiceninja.com/en/latest/update.html

OK will try the upgrade again with the copied .env file.

Maybe it’s good to have a short message on the update screen to warn about .env file not found - existing database will be overridden (something like that). I was expecting process to be like Wordpress update where the update screen actually updates the wpdb with the data intact :slight_smile:

Thanks for your prompt response.

Hello again,

I copied .env to the folder for v3.3.3 and making sure to change APP_CIPHER=rijndael-128 before that.

When I refreshed the page, I got to the new login screen but upon logging in it says “Whoops there’s something wrong”.

I then proceeded to enable APP_DEBUG=true and manually proceeded to the /update page and it returned this error:

SQLSTATE[HY000]: General error: 1005 Can’t create table ninja.#sql-4ff3_100e (errno: 150 “Foreign key constraint is incorrectly formed”) (SQL: alter table payment_methods add constraint payment_methods_account_gateway_token_id_foreign foreign key (account_gateway_token_id) references account_gateway_tokens (id))

So I am back to 2.5.2.2 again.

This is the copy of my .env file (with passwords/domains removed):

PATH=/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin
PWD=/usr/local/cpanel/cgi-sys
SHLVL=0
SCRIPT_NAME=/ninja/public/index.php
REQUEST_URI=/update_setup
QUERY_STRING=
REQUEST_METHOD=POST
SERVER_PROTOCOL=HTTP/1.1
GATEWAY_INTERFACE=CGI/1.1
REDIRECT_URL=/index.php
REMOTE_PORT=63622
SCRIPT_FILENAME=/home/path/public_html/invoices/ninja/public/index.php
SERVER_ADMIN=webmaster@invoices.example.com
CONTEXT_DOCUMENT_ROOT=/home/path/public_html/invoices
CONTEXT_PREFIX=
REQUEST_SCHEME=http
DOCUMENT_ROOT=/home/path/public_html/invoices
REMOTE_ADDR=x.x.x.x
SERVER_PORT=80
SERVER_ADDR=x.x.x.x
SERVER_NAME=invoices.example.com
SERVER_SOFTWARE=Apache
SERVER_SIGNATURE=
LD_LIBRARY_PATH=/usr/local/apache/lib
HTTP_COOKIE=‘remember_user_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6IkZPRDJORVdXaU55XC9zTzM1enV0bHRnPT0iLCJ2YWx1ZSI6Im53enpWSVhqYUNaNW1JUVhcL1FSdjc2a1BkM3ZxbXlCbnRHTDJkVldzbHVPTVNlNkx5bVc4NE5BMmdoaVhCUUpZTDZ4SW83SVZ0azZWNGt4VVFzY0dSZGswdDlvZ3EwYVBydWNZc2dOeVdPVT0iLCJtYWMiOiJhZjkwMDExODkxODY4YjNjNGNhM2FkZjM1ZTk2ZTU5MGJlNTM0ZWM5MDVhMzE2NTI5ODlkNjc0ZWExZGUyZWQ5In0%3D; XSRF-TOKEN=eyJpdiI6IkFUaWhCNkNkUlZSVUdjbnpKbFhiTFE9PSIsInZhbHVlIjoiYkZKdm9kOE1Ld1JMeEtZcUJiSEowaTFveTNzWXhtcHNCcFk4RWdaaUZnK2k3d2xWWnJGNnp3ZmlmbFpnWnpySnJFNlJMUUwwWEpKalBzNkFka0JrdVE9PSIsIm1hYyI6IjRkMzBhMjNjMTIwN2IxMDg3ZGI2Y2I0MWYzMDdlZDNiMzZiOGU3ZjI1ZDlhYjE2OTgwMjkyZmU4YzE5NDY3ZTAifQ%3D%3D; ninja_session=eyJpdiI6IlI5Nlk0Y1NidldUYlNnalR6blBmNFE9PSIsInZhbHVlIjoiYjlXaWpxUGEydytCZzhKUXpaczJmSlRIQ0lZK3laNUZ2eUY2NERuWkR0VWxMUDJNSERXc3NmWWthUm5wSjcwclA1MlVzdzRPVCtaMlFBQVwvNThBaUJnPT0iLCJtYWMiOiJjZjgyNzI1OTQ5NGE0YzY3NjliYzA5MWEyYzBhYjdkZmZmNTU5Mjk4MDA4YzJhNWRkNDJmMWQ4NjYxOTU1OTkzIn0%3D’
HTTP_ACCEPT_LANGUAGE=en-US,en;q=0.8
HTTP_ACCEPT_ENCODING=‘gzip, deflate’
HTTP_REFERER=http://invoices.example.com/settings/system_settings
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
CONTENT_TYPE=application/x-www-form-urlencoded
HTTP_USER_AGENT=‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36’
HTTP_UPGRADE_INSECURE_REQUESTS=1
HTTP_ORIGIN=http://invoices.example.com
HTTP_CACHE_CONTROL=max-age=0
CONTENT_LENGTH=471
HTTP_CONNECTION=close
HTTP_HOST=invoices.example.com
UNIQUE_ID=V4eGesvTkd0AAC@9DdQAAACN
REDIRECT_STATUS=200
REDIRECT_UNIQUE_ID=V4eGesvTkd0AAC@9DdQAAACN
REDIRECT_REDIRECT_STATUS=200
REDIRECT_REDIRECT_UNIQUE_ID=V4eGesvTkd0AAC@9DdQAAACN
REDIRECT_REDIRECT_REDIRECT_STATUS=200
REDIRECT_REDIRECT_REDIRECT_UNIQUE_ID=V4eGesvTkd0AAC@9DdQAAACN
FCGI_ROLE=RESPONDER
PHP_SELF=/ninja/public/index.php
REQUEST_TIME_FLOAT=1468499578.78
REQUEST_TIME=1468499578
argc=0
APP_ENV=production
APP_DEBUG=true
APP_LOCALE=en
APP_URL=https://invoices.example.com
APP_CIPHER=AES-256-CBC
APP_KEY=<removed>
DB_TYPE=mysql
DB_STRICT=false
DB_HOST=localhost
DB_DATABASE=ninja
DB_USERNAME=ninja
DB_PASSWORD=<removed>
MAIL_DRIVER=smtp
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
PHANTOMJS_CLOUD_KEY=a-demo-key-with-low-quota-per-ip-address
LOG=single
REQUIRE_HTTPS=true
API_SECRET=password
MAIL_HOST=vps.example.com
MAIL_USERNAME=admin@example.com
MAIL_FROM_NAME=‘Invoicer’
MAIL_PASSWORD=<removed>
MAIL_FROM_ADDRESS=admin@example.com

I’m not sure, if you want to email a copy of your database to contact@invoicennja.com I can try to replicate the problem.

I’ve been able to get the upgrade to complete by commenting out line 71 in database/migrations/2016_04_23_182223_payments_changes.php

$table->foreign(‘account_gateway_token_id’)->references(‘id’)->on(‘account_gateway_tokens’);