Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pq: column "adv_account_sig_key" does not exist #404

Open
devalexandre opened this issue Jun 12, 2023 · 8 comments
Open

pq: column "adv_account_sig_key" does not exist #404

devalexandre opened this issue Jun 12, 2023 · 8 comments

Comments

@devalexandre
Copy link

I'm using _ "github.com/lib/pq" but when I run display a error

18:33:47.612 [Database INFO] Upgrading database to v1
18:33:49.908 [Database INFO] Upgrading database to v2
panic: failed to upgrade database: pq: column "adv_account_sig_key" does not exist
container, err := sqlstore.New("postgres", config.GetDataBaseDNS(), dbLog)
@tulir
Copy link
Owner

tulir commented Jun 12, 2023

Are you using some weird postgres-ish server like cockroachdb?

@devalexandre
Copy link
Author

Are you using some weird postgres-ish server like cockroachdb?

I'm using cockroachdb serverless, but in the local postgres it gives the same error

@tulir
Copy link
Owner

tulir commented Jun 13, 2023

It works fine on real postgres, cockroach won't work right now because schema migrations aren't synchronous there.

@fnxln
Copy link

fnxln commented Sep 25, 2023

having same problem on real postgres 15.4

@Mauricio-Carrion
Copy link

Same trying to use cockroachdb here

@Mauricio-Carrion
Copy link

The error just ocurrs on upgrading database to v2 migration.

image

@Mauricio-Carrion
Copy link

In cockroachdb panel seems everthing right

image

@Mauricio-Carrion
Copy link

Now I extract the SQL statatements using ChatGPT from store/sqlstore/upgrade.go

CREATE TABLE IF NOT EXISTS whatsmeow_version (version INTEGER);

SELECT version FROM whatsmeow_version LIMIT 1;

DELETE FROM whatsmeow_version;

INSERT INTO whatsmeow_version (version) VALUES ($1);

CREATE TABLE whatsmeow_device (
    jid TEXT PRIMARY KEY,
    registration_id BIGINT NOT NULL CHECK (registration_id >= 0 AND registration_id < 4294967296),
    noise_key bytea NOT NULL CHECK (length(noise_key) = 32),
    identity_key bytea NOT NULL CHECK (length(identity_key) = 32),
    signed_pre_key bytea NOT NULL CHECK (length(signed_pre_key) = 32),
    signed_pre_key_id INTEGER NOT NULL CHECK (signed_pre_key_id >= 0 AND signed_pre_key_id < 16777216),
    signed_pre_key_sig bytea NOT NULL CHECK (length(signed_pre_key_sig) = 64),
    adv_key bytea NOT NULL,
    adv_details bytea NOT NULL,
    adv_account_sig bytea NOT NULL CHECK (length(adv_account_sig) = 64),
    adv_device_sig bytea NOT NULL CHECK (length(adv_device_sig) = 64),
    platform TEXT NOT NULL DEFAULT '',
    business_name TEXT NOT NULL DEFAULT '',
    push_name TEXT NOT NULL DEFAULT ''
);

CREATE TABLE whatsmeow_identity_keys (
    our_jid TEXT,
    their_id TEXT,
    identity bytea NOT NULL CHECK (length(identity) = 32),
    PRIMARY KEY (our_jid, their_id),
    FOREIGN KEY (our_jid) REFERENCES whatsmeow_device(jid) ON DELETE CASCADE ON UPDATE CASCADE
);

-- Other CREATE TABLE statements similar to the ones above.

ALTER TABLE whatsmeow_device ADD COLUMN adv_account_sig_key bytea CHECK (length(adv_account_sig_key) = 32);

UPDATE whatsmeow_device SET adv_account_sig_key = (
    SELECT identity FROM whatsmeow_identity_keys
    WHERE our_jid = whatsmeow_device.jid AND their_id = concat(split_part(whatsmeow_device.jid, '.', 1), ':0')
);

-- Other SQL statements for PostgreSQL or SQLite specific updates.

CREATE TABLE whatsmeow_message_secrets (
    our_jid TEXT,
    chat_jid TEXT,
    sender_jid TEXT,
    message_id TEXT,
    key bytea NOT NULL,
    PRIMARY KEY (our_jid, chat_jid, sender_jid, message_id),
    FOREIGN KEY (our_jid) REFERENCES whatsmeow_device(jid) ON DELETE CASCADE ON UPDATE CASCADE
);

But the real problem is here:
image

image

Apparantly cockroachdb doesn't runs update and delete on databases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants