Skip to content

Commit

Permalink
ensure history table is created with Postgraphile 'omit' annotation i…
Browse files Browse the repository at this point in the history
…f needed
  • Loading branch information
sduchesneau committed Nov 6, 2023
1 parent 3558854 commit 28197f7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (l *Loader) Setup(ctx context.Context, schemaBytes []byte, withPostgraphile
return fmt.Errorf("setup cursor table: %w", err)
}

if err := l.setupHistoryTable(ctx); err != nil {
if err := l.setupHistoryTable(ctx, withPostgraphile); err != nil {
return fmt.Errorf("setup history table: %w", err)
}

Expand All @@ -300,11 +300,11 @@ func (l *Loader) setupCursorTable(ctx context.Context, withPostgraphile bool) er
return err
}

func (l *Loader) setupHistoryTable(ctx context.Context) error {
func (l *Loader) setupHistoryTable(ctx context.Context, withPostgraphile bool) error {
if l.getDialect().OnlyInserts() {
return nil
}
query := l.getDialect().GetCreateHistoryQuery(l.schema)
query := l.getDialect().GetCreateHistoryQuery(l.schema, withPostgraphile)
_, err := l.ExecContext(ctx, query)
return err
}
Expand Down
2 changes: 1 addition & 1 deletion db/dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (e UnknownDriverError) Error() string {

type dialect interface {
GetCreateCursorQuery(schema string, withPostgraphile bool) string
GetCreateHistoryQuery(schema string) string
GetCreateHistoryQuery(schema string, withPostgraphile bool) string
ExecuteSetupScript(ctx context.Context, l *Loader, schemaSql string) error
DriverSupportRowsAffected() bool
GetUpdateCursorQuery(table, moduleHash string, cursor *sink.Cursor, block_num uint64, block_id string) string
Expand Down
2 changes: 1 addition & 1 deletion db/dialect_clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (d clickhouseDialect) GetCreateCursorQuery(schema string, withPostgraphile
`), EscapeIdentifier(schema), EscapeIdentifier(CURSORS_TABLE))
}

func (d clickhouseDialect) GetCreateHistoryQuery(schema string) string {
func (d clickhouseDialect) GetCreateHistoryQuery(schema string, withPostgraphile bool) string {
panic("clickhouse does not support reorg management")
}

Expand Down
6 changes: 5 additions & 1 deletion db/dialect_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (d postgresDialect) GetCreateCursorQuery(schema string, withPostgraphile bo
return out
}

func (d postgresDialect) GetCreateHistoryQuery(schema string) string {
func (d postgresDialect) GetCreateHistoryQuery(schema string, withPostgraphile bool) string {
out := fmt.Sprintf(cli.Dedent(`
create table if not exists %s
(
Expand All @@ -203,6 +203,10 @@ func (d postgresDialect) GetCreateHistoryQuery(schema string) string {
`),
d.historyTable(schema),
)
if withPostgraphile {
out += fmt.Sprintf("COMMENT ON TABLE %s.%s IS E'@omit';",
EscapeIdentifier(schema), EscapeIdentifier(HISTORY_TABLE))
}
return out
}

Expand Down

0 comments on commit 28197f7

Please sign in to comment.