Zondax / namadexer

Namada indexer
39 stars 57 forks source link

Error on newest version on start (views) #181

Closed opsecx closed 7 months ago

opsecx commented 7 months ago

As mentioned to Lola previously, an error might occur on changing the views, which is exactly what's happening now (preventing start).

Scenario:

  1. Having had the recent versions with views lacking certain fields/columns in db
  2. Install newest updated version that adds certain columns to views

Causes the following error: "Error: DB(Database(PgDatabaseError { severity: Error, code: "42P16", message: "cannot change name of view column \"address\" to \"txid\"", detail: None, hint: Some("Use ALTER VIEW ... RENAME COLUMN ... to change name of view column instead."), position: None, where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("view.c"), line: Some(293), routine: Some("checkViewTupleDesc") }))"

Which prevents indexer from starting altogether.

Obviously this can be amended by dropping all views manually before starting indexer, but recommended fix in code by dropping or altering views appropriately, taking into account the possibility of former data structures in db. (feel free to reach out directly if the issue isn't clear)

opsecx commented 7 months ago

Gonna try and POC this and make a PR if it works, if you don't mind

opsecx commented 7 months ago

Put in a PR as above. Tested and works fine as best I can tell, but up to you guys if wanted solution. In any case there is an issue with any databases that have been updated the last two weeks with this..

rllola commented 7 months ago

Hey! So indeed I misread the postgres doc (https://www.postgresql.org/docs/current/sql-createview.html). We are using CREATE OR REPLACE VIEW but there is is some conditions to it : but it may add additional columns to the end of the list. and I have made the mistake to add it at the beginning...

I am going to approve your PR.

rllola commented 7 months ago

fixed in #182