Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ linters:
- durationcheck
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gochecknoinits
- goconst
Expand Down
6 changes: 2 additions & 4 deletions internal/infra/postgresql/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (p Postgres) FinalizePartitionDetach(schema, table, parent string) error {
query := fmt.Sprintf(`ALTER TABLE %s DETACH PARTITION %s FINALIZE`,
pgx.Identifier{schema, parent}.Sanitize(),
pgx.Identifier{schema, table}.Sanitize())
p.logger.Debug("finialize detach partition", "schema", schema, "table", table, "query", query, "parent_table", parent)
p.logger.Debug("finalize detach partition", "schema", schema, "table", table, "query", query, "parent_table", parent)

_, err := p.conn.Exec(p.ctx, query)
if err != nil {
Expand Down Expand Up @@ -141,9 +141,7 @@ func (p Postgres) GetPartitionSettings(schema, table string) (strategy, key stri
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = $1 AND c.relname = $2 AND c.relkind='p')) as partkeydef
`

err = p.conn.QueryRow(p.ctx, query, schema, table).Scan(&partkeydef)
if err != nil {
if err = p.conn.QueryRow(p.ctx, query, schema, table).Scan(&partkeydef); err != nil {
p.logger.Warn("failed to get partitioning key", "error", err, "schema", schema, "table", table)

return "", "", fmt.Errorf("failed to get partition key: %w", err)
Expand Down
22 changes: 12 additions & 10 deletions pkg/ppm/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (p PPM) ProvisioningPartitions() error {
p.logger.Info("Provisioning partition", "partition", name)

if err := p.provisionPartitionsFor(config, p.workDate); err != nil {
p.logger.Error("Failed to provision partitions", "error", err, "schema", config.Schema, "table", config.Table)

provisioningFailed = true
}
}
Expand Down Expand Up @@ -104,6 +106,16 @@ func (p PPM) provisionPartitionsFor(config partition.Configuration, at time.Time
func (p PPM) CreatePartition(partitionConfiguration partition.Configuration, partition partition.Partition) error {
p.logger.Debug("Creating partition", "schema", partition.Schema, "table", partition.Name)

_, partitionKey, err := p.db.GetPartitionSettings(partition.Schema, partition.ParentTable)
if err != nil {
return fmt.Errorf("failed to get partition settings: %w", err)
}

partitionKeyType, err := p.db.GetColumnDataType(partition.Schema, partition.ParentTable, partitionKey)
if err != nil {
return fmt.Errorf("failed to get partition key details: %w", err)
}

tableExists, err := p.db.IsTableExists(partition.Schema, partition.Name)
if err != nil {
return fmt.Errorf("failed to check if table exists: %w", err)
Expand Down Expand Up @@ -131,16 +143,6 @@ func (p PPM) CreatePartition(partitionConfiguration partition.Configuration, par
return nil
}

_, partitionKey, err := p.db.GetPartitionSettings(partition.Schema, partition.ParentTable)
if err != nil {
return fmt.Errorf("failed to get partition settings: %w", err)
}

partitionKeyType, err := p.db.GetColumnDataType(partition.Schema, partition.ParentTable, partitionKey)
if err != nil {
return fmt.Errorf("failed to get partition settings: %w", err)
}

var lowerBound, upperBound string

switch partitionKeyType {
Expand Down
Loading