feat(indexer): add to modules and implement proto fields (#22544)

This commit is contained in:
Facundo Medica
2024-11-28 09:46:59 +00:00
committed by GitHub
parent 18dcdb8f45
commit bd76b47e1d
74 changed files with 622 additions and 131 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ func (tm *objectIndexer) createTable(ctx context.Context, conn dbConn) error {
sqlStr := buf.String()
if tm.options.logger != nil {
tm.options.logger.Debug("Creating table %s", "table", tm.tableName(), "sql", sqlStr)
tm.options.logger.Debug("Creating table", "table", tm.tableName(), "sql", sqlStr)
}
_, err = conn.ExecContext(ctx, sqlStr)
return err
+1
View File
@@ -21,6 +21,7 @@ func (m *moduleIndexer) createEnumType(ctx context.Context, conn dbConn, enum sc
}
} else {
// the enum type already exists
// TODO: add a check to ensure the existing enum type matches the expected values, and update it if necessary?
return nil
}
+20 -1
View File
@@ -22,7 +22,26 @@ func (i *indexerImpl) listener() appdata.Listener {
return mm.initializeSchema(i.ctx, i.tx)
},
StartBlock: func(data appdata.StartBlockData) error {
_, err := i.tx.Exec("INSERT INTO block (number) VALUES ($1)", data.Height)
var (
headerBz []byte
err error
)
if data.HeaderJSON != nil {
headerBz, err = data.HeaderJSON()
if err != nil {
return err
}
} else if data.HeaderBytes != nil {
headerBz, err = data.HeaderBytes()
if err != nil {
return err
}
}
// TODO: verify the format of headerBz, otherwise we'll get `ERROR: invalid input syntax for type json (SQLSTATE 22P02)`
_, err = i.tx.Exec("INSERT INTO block (number, header) VALUES ($1, $2)", data.Height, headerBz)
return err
},
OnObjectUpdate: func(data appdata.ObjectUpdateData) error {
+3 -3
View File
@@ -6,7 +6,7 @@ DEBUG: Creating enum type
sql: CREATE TYPE "test_my_enum" AS ENUM ('a', 'b', 'c');
DEBUG: Creating enum type
sql: CREATE TYPE "test_vote_type" AS ENUM ('yes', 'no', 'abstain');
DEBUG: Creating table %s
DEBUG: Creating table
table: test_all_kinds
sql: CREATE TABLE IF NOT EXISTS "test_all_kinds" (
"id" BIGINT NOT NULL,
@@ -36,7 +36,7 @@ DEBUG: Creating table %s
PRIMARY KEY ("id", "ts_nanos")
);
GRANT SELECT ON TABLE "test_all_kinds" TO PUBLIC;
DEBUG: Creating table %s
DEBUG: Creating table
table: test_singleton
sql: CREATE TABLE IF NOT EXISTS "test_singleton" (
_id INTEGER NOT NULL CHECK (_id = 1),
@@ -46,7 +46,7 @@ DEBUG: Creating table %s
PRIMARY KEY (_id)
);
GRANT SELECT ON TABLE "test_singleton" TO PUBLIC;
DEBUG: Creating table %s
DEBUG: Creating table
table: test_vote
sql: CREATE TABLE IF NOT EXISTS "test_vote" (
"proposal" BIGINT NOT NULL,
@@ -6,7 +6,7 @@ DEBUG: Creating enum type
sql: CREATE TYPE "test_my_enum" AS ENUM ('a', 'b', 'c');
DEBUG: Creating enum type
sql: CREATE TYPE "test_vote_type" AS ENUM ('yes', 'no', 'abstain');
DEBUG: Creating table %s
DEBUG: Creating table
table: test_all_kinds
sql: CREATE TABLE IF NOT EXISTS "test_all_kinds" (
"id" BIGINT NOT NULL,
@@ -36,7 +36,7 @@ DEBUG: Creating table %s
PRIMARY KEY ("id", "ts_nanos")
);
GRANT SELECT ON TABLE "test_all_kinds" TO PUBLIC;
DEBUG: Creating table %s
DEBUG: Creating table
table: test_singleton
sql: CREATE TABLE IF NOT EXISTS "test_singleton" (
_id INTEGER NOT NULL CHECK (_id = 1),
@@ -46,7 +46,7 @@ DEBUG: Creating table %s
PRIMARY KEY (_id)
);
GRANT SELECT ON TABLE "test_singleton" TO PUBLIC;
DEBUG: Creating table %s
DEBUG: Creating table
table: test_vote
sql: CREATE TABLE IF NOT EXISTS "test_vote" (
"proposal" BIGINT NOT NULL,