actualbudget / actual

A local-first personal finance app
https://actualbudget.org
MIT License
14.25k stars 1.14k forks source link

[Bug]: Database is out of sync with migrations #2406

Closed wirhabenzeit closed 7 months ago

wirhabenzeit commented 7 months ago

Verified issue does not already exist?

Is this related to GoCardless, Simplefin or another bank-sync provider?

What happened?

I tried using the API using

import {
  init,
  downloadBudget,
  getBudgetMonth,
  shutdown,
} from "@actual-app/api";

const importer = async () => {
  await init({
    serverURL: process.env.SERVER_URL,
    password: process.env.SERVER_PASSWORD,
  });
  await downloadBudget(process.env.BUDGET_SYNC_ID);
  let budget = await getBudgetMonth("2023-12");
  console.log(budget);
  await shutdown();
};

importer();

but am receiving an error at the downloadBudget step. I am using @actual-app/api@6.4.0 and my settings page shows

Actual is a super fast privacy-focused app for managing your finances.
Client version: v24.2.0
Server version: N/A
You’re up to date!
[Release Notes](https://actualbudget.org/docs/releases)

I am a bit confused by the N/A, I just used installed the latest version using docker compose with the image docker.io/actualbudget/actual-server:edge-alpine

What error did you receive?

% node --env-file=.env --trace-warnings app.mjs 
(node:53395) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
    at getAllowUnauthorized (node:internal/options:58:13)
    at Object.connect (node:_tls_wrap:1743:29)
    at Client.connect (node:internal/deps/undici/undici:6793:24)
    at socket (node:internal/deps/undici/undici:8339:29)
    at new Promise (<anonymous>)
    at connect (node:internal/deps/undici/undici:8338:30)
    at _resume (node:internal/deps/undici/undici:8534:11)
    at resume (node:internal/deps/undici/undici:8459:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
Database is out of sync with migrations: {
  appliedIds: [
    1548957970627, 1550601598648,
    1555786194328, 1561751833510,
    1567699552727, 1582384163573,
    1597756566448, 1608652596043,
    1608652596044, 1612625548236,
    1614782639336, 1615745967948,
    1616167010796, 1618975177358,
    1632571489012, 1679728867040,
    1681115033845, 1682974838138,
    1685007876842, 1686139660866,
    1688749527273, 1688841238000,
    1691233396000, 1694438752000,
    1697046240000, 1704572023730,
    1704572023731, 1707267033000
  ],
  available: [
    '1548957970627_remove-db-version.sql',
    '1550601598648_payees.sql',
    '1555786194328_remove_category_group_unique.sql',
    '1561751833510_indexes.sql',
    '1567699552727_budget.sql',
    '1582384163573_cleared.sql',
    '1597756566448_rules.sql',
    '1608652596043_parent_field.sql',
    '1608652596044_trans_views.sql',
    '1612625548236_optimize.sql',
    '1614782639336_trans_views2.sql',
    '1615745967948_meta.sql',
    '1616167010796_accounts_order.sql',
    '1618975177358_schedules.sql',
    '1632571489012_remove_cache.js',
    '1679728867040_rules_conditions.sql',
    '1681115033845_add_schedule_name.sql',
    '1682974838138_remove_payee_rules.sql',
    '1685007876842_add_category_hidden.sql',
    '1686139660866_remove_account_type.sql',
    '1688749527273_transaction_filters.sql',
    '1688841238000_add_account_type.sql',
    '1691233396000_add_schedule_next_date_tombstone.sql',
    '1694438752000_add_goal_targets.sql',
    '1697046240000_add_reconciled.sql'
  ]
}
Error updating Error: out-of-sync-migrations
    at checkDatabaseValidity (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:44190:31)
    at Module.migrate (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:44198:17)
    at async runMigrations (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47908:17)
    at async updateVersion (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47927:17)
    at async loadBudget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:43796:21)
    at async handlers.load-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:43626:29)
    at async handlers.api/download-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:34702:21)
TypeError: Cannot read properties of undefined (reading 'timestamp')
    at _fullSync (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47257:98)
    at /Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47169:38
    at /Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:48104:38
    at initialFullSync (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47155:38)
    at handlers.sync-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:43611:94)
    at handlers.api/download-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:34705:65)
[Exception] TypeError: Cannot read properties of undefined (reading 'timestamp')
    at _fullSync (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47257:98)
    at /Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47169:38
    at /Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:48104:38
    at initialFullSync (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:47155:38)
    at handlers.sync-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:43611:94)
    at handlers.api/download-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:34705:65)
/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:34707
                        throw new Error((0, _shared_errors__WEBPACK_IMPORTED_MODULE_2__.getSyncError)(result.error, localBudget.id));
                              ^

Error: We had an unknown problem opening “My-Finances-abae71b”.
    at handlers.api/download-budget (/Users/user/Documents/bank-importer/node_modules/@actual-app/api/dist/app/bundle.api.js:34707:31)

Node.js v20.10.0

Where are you hosting Actual?

Docker

What browsers are you seeing the problem on?

No response

Operating System

Linux

Teprifer commented 7 months ago

There was a db change recently merged into edge, these aren't common but you may want to use the latest tag rather than edge.

My understanding of the process is this should resolve shortly as a new release isn't far away.

https://github.com/actualbudget/actual/pull/2335#pullrequestreview-1883873872

wirhabenzeit commented 7 months ago

I changed the docker-compose.yml file to docker.io/actualbudget/actual-server:latest-alpine and restarted the container. Now the settings page shows

Actual is a super fast privacy-focused app for managing your finances.
Client version: v24.2.0
Server version: v24.2.0
You’re up to date!
[Release Notes](https://actualbudget.org/docs/releases)

so no N/A anymore. However, the Database is out of sync with migrations error above is still occurring.

youngcw commented 7 months ago

you probably still have migrations in your file so the api wont work until the next release, when the api is updated. The way to unbreak things is to use a backup from before you used edge to not have those migrations in the file then the api will work again.

tiagodj commented 7 months ago

So, I was having this problem too. After debugging, I came down to find out that this only happens in node v18. If you use node v20 it works. The issue for me is that I run in node-red, and node-red docker images don't have support for node v20 yet.