Revert "WIP: We need to find a solution because CockroachDB doesn't support UDFs"
This reverts commit e4b3fbdf26
.
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is contained in:
parent
e4b3fbdf26
commit
c5e9ae0a98
|
@ -64,7 +64,6 @@ type Options struct {
|
|||
type MigrateOptions struct {
|
||||
Logger logger.Logger
|
||||
StateTableName string
|
||||
KeyPrefixFuncName string
|
||||
MetadataTableName string
|
||||
}
|
||||
|
||||
|
@ -121,7 +120,6 @@ func (p *PostgreSQL) Init(ctx context.Context, meta state.Metadata) error {
|
|||
err = p.migrateFn(ctx, p.db, MigrateOptions{
|
||||
Logger: p.logger,
|
||||
StateTableName: p.metadata.TableName,
|
||||
KeyPrefixFuncName: p.metadata.TableName + "_key_prefix",
|
||||
MetadataTableName: p.metadata.MetadataTableName,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -54,7 +54,6 @@ func (p *PostgreSQLQuery) Features() []state.Feature {
|
|||
state.FeatureTransactional,
|
||||
state.FeatureQueryAPI,
|
||||
state.FeatureTTL,
|
||||
state.FeatureDeleteWithPrefix,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ capabilities:
|
|||
- etag
|
||||
- query
|
||||
- ttl
|
||||
- deleteWithPrefix
|
||||
builtinAuthenticationProfiles:
|
||||
- name: "azuread"
|
||||
metadata:
|
||||
|
|
|
@ -39,14 +39,14 @@ func performMigrations(ctx context.Context, db pginterfaces.PGXPoolConn, opts po
|
|||
opts.Logger.Infof("Creating state table '%s'", opts.StateTableName)
|
||||
_, err := db.Exec(
|
||||
ctx,
|
||||
fmt.Sprintf(`
|
||||
CREATE TABLE IF NOT EXISTS %s (
|
||||
key text NOT NULL PRIMARY KEY,
|
||||
value jsonb NOT NULL,
|
||||
isbinary boolean NOT NULL,
|
||||
insertdate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||
updatedate TIMESTAMP WITH TIME ZONE NULL
|
||||
)`,
|
||||
fmt.Sprintf(
|
||||
`CREATE TABLE IF NOT EXISTS %s (
|
||||
key text NOT NULL PRIMARY KEY,
|
||||
value jsonb NOT NULL,
|
||||
isbinary boolean NOT NULL,
|
||||
insertdate TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||
updatedate TIMESTAMP WITH TIME ZONE NULL
|
||||
)`,
|
||||
opts.StateTableName,
|
||||
),
|
||||
)
|
||||
|
@ -68,31 +68,6 @@ CREATE TABLE IF NOT EXISTS %s (
|
|||
}
|
||||
return nil
|
||||
},
|
||||
// Migration 2: add the "key_prefix" function and "prefix" index to the state table
|
||||
func(ctx context.Context) error {
|
||||
// Create the "key_prefix" function
|
||||
// Then add the "prefix" index to the state table that can be used by DeleteWithPrefix
|
||||
opts.Logger.Infof("Creating function '%s' and adding 'prefix' index to table '%s'", opts.KeyPrefixFuncName, opts.StateTableName)
|
||||
_, err := db.Exec(
|
||||
ctx,
|
||||
fmt.Sprintf(`
|
||||
CREATE FUNCTION %[1]s(k text) RETURNS text
|
||||
LANGUAGE SQL
|
||||
IMMUTABLE
|
||||
LEAKPROOF
|
||||
RETURNS NULL ON NULL INPUT
|
||||
RETURN
|
||||
array_to_string(trim_array(string_to_array(k, '||'),1), '||');
|
||||
|
||||
CREATE INDEX %[2]s_prefix_idx ON %[2]s (%[1]s("key")) WHERE %[1]s("key") <> '';
|
||||
`,
|
||||
opts.KeyPrefixFuncName, opts.StateTableName,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create virtual column: %w", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -14,9 +14,6 @@ limitations under the License.
|
|||
package postgresql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
postgresql "github.com/dapr/components-contrib/common/component/postgresql/v1"
|
||||
"github.com/dapr/components-contrib/state"
|
||||
"github.com/dapr/kit/logger"
|
||||
|
@ -64,33 +61,3 @@ func NewPostgreSQLStateStore(logger logger.Logger) state.Store {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
// PostgreSQLStoreWithDeleteWithPrefix is a state store for PostgreSQL that implements the DeleteWithPrefix method
|
||||
type PostgreSQLStoreWithDeleteWithPrefix struct {
|
||||
state.Store
|
||||
}
|
||||
|
||||
// Features returns the features available in this state store.
|
||||
func (p *PostgreSQLStoreWithDeleteWithPrefix) Features() []state.Feature {
|
||||
return append(p.Store.Features(), state.FeatureDeleteWithPrefix)
|
||||
}
|
||||
|
||||
func (p *PostgreSQLStoreWithDeleteWithPrefix) DeleteWithPrefix(ctx context.Context, req state.DeleteWithPrefixRequest) (state.DeleteWithPrefixResponse, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return state.DeleteWithPrefixResponse{}, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, p.metadata.Timeout)
|
||||
defer cancel()
|
||||
|
||||
// Trim the trailing "||" from the prefix
|
||||
result, err := p.db.Exec(ctx, "DELETE FROM "+p.metadata.TableName+" WHERE "+p.metadata.TableName+`_key_prefix("key") = $1`, strings.TrimSuffix(req.Prefix, "||"))
|
||||
if err != nil {
|
||||
return state.DeleteWithPrefixResponse{}, err
|
||||
}
|
||||
|
||||
return state.DeleteWithPrefixResponse{
|
||||
Count: result.RowsAffected(),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -35,12 +35,12 @@ components:
|
|||
# This component requires etags to be hex-encoded numbers
|
||||
badEtag: "FFFF"
|
||||
- component: postgresql.v1.docker
|
||||
operations: [ "transaction", "etag", "first-write", "query", "ttl", "delete-with-prefix" ]
|
||||
operations: [ "transaction", "etag", "first-write", "query", "ttl" ]
|
||||
config:
|
||||
# This component requires etags to be numeric
|
||||
badEtag: "1"
|
||||
- component: postgresql.v1.azure
|
||||
operations: [ "transaction", "etag", "first-write", "query", "ttl", "delete-with-prefix" ]
|
||||
operations: [ "transaction", "etag", "first-write", "query", "ttl" ]
|
||||
config:
|
||||
# This component requires etags to be numeric
|
||||
badEtag: "1"
|
||||
|
|
Loading…
Reference in New Issue