OS2iot / OS2iot-backend

This repository contains the backend to the project OS2iot.
Mozilla Public License 2.0
10 stars 7 forks source link

Update from v.1.0.1 to Staging fails #142

Closed bkd231 closed 2 years ago

bkd231 commented 2 years ago

When running the staging version of the OS2IoT backend with the DB from Release v.1.0.1 we are getting the error:

...
0 migrations are already loaded in the database.
3 migrations were found in the source code.
3 migrations are new migrations that needs to be executed.
...
Error during migration run:
QueryFailedError: relation "open_data_dk_dataset" already exists

To reproduce this please run the Release v.1.0.1 version of the backend with a new database and then run the Stage on the same DB.

GufCab commented 2 years ago

Thank you for the input - I will fix this before releasing version 1.1.0 with the current code on stage.

GufCab commented 2 years ago

I am closing this issue as this is a known "breaking change" in the next release. I'll add it specifically to the release notes and the documentation.

The reason is that the original project used TypeORMs synchronize feature and we have now switched to using explicit migrations. This includes an initial migration which creates all the tables as they looked in v.1.0.1 - this enables new installations of OS2iot but leaves an issue for existing instances that has already had the database auto-synched.

The "fix" for existing installations is:

  1. Manually create table "migrations"
  2. Add row with the initial migration

Essentially, run this SQL Script:

CREATE TABLE migrations (
   id SERIAL PRIMARY KEY,
   timestamp BIGINT NOT NULL,
   name varchar NOT NULL   
);

INSERT INTO migrations (timestamp, name)
VALUES (1, 'Initial0000000000001')

Then the two real migrations will run properly and the issue won't arise again.