Compare commits
2
Commits
1cfd062835
...
v1.14.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
930e42b0b0 | ||
|
|
16b4923bd7 |
No files matched your search
@@ -39,7 +39,7 @@ func (p *Postgres) GetModulePrefixSnapshot(tenantID, moduleID string) (*store.Mo
|
|||||||
var prefixes []store.PrefixRow
|
var prefixes []store.PrefixRow
|
||||||
if moduleSnapshotRowTableExists(ctx, p.pool) {
|
if moduleSnapshotRowTableExists(ctx, p.pool) {
|
||||||
rows, qerr := p.pool.Query(ctx, `
|
rows, qerr := p.pool.Query(ctx, `
|
||||||
SELECT prefix::text, community_id::text, source
|
SELECT prefix, community_id::text, source
|
||||||
FROM module_prefix_snapshot_row
|
FROM module_prefix_snapshot_row
|
||||||
WHERE tenant_id = $1::uuid AND module_id = $2::uuid
|
WHERE tenant_id = $1::uuid AND module_id = $2::uuid
|
||||||
ORDER BY ord`, tenantID, moduleID)
|
ORDER BY ord`, tenantID, moduleID)
|
||||||
@@ -108,7 +108,7 @@ func (p *Postgres) SetModulePrefixSnapshot(tenantID, moduleID, inputHash string,
|
|||||||
}
|
}
|
||||||
if _, err := tx.Exec(ctx, `
|
if _, err := tx.Exec(ctx, `
|
||||||
INSERT INTO module_prefix_snapshot_row (tenant_id, module_id, ord, prefix, community_id, source)
|
INSERT INTO module_prefix_snapshot_row (tenant_id, module_id, ord, prefix, community_id, source)
|
||||||
VALUES ($1::uuid, $2::uuid, $3, $4::cidr, $5::uuid, $6)`,
|
VALUES ($1::uuid, $2::uuid, $3, $4, $5::uuid, $6)`,
|
||||||
tenantID, moduleID, i, strings.TrimSpace(pr.Prefix), comm, src); err != nil {
|
tenantID, moduleID, i, strings.TrimSpace(pr.Prefix), comm, src); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func (p *Postgres) ensurePrefixSnapshot(ctx context.Context, db execQuerier, con
|
|||||||
}
|
}
|
||||||
if _, err := db.Exec(ctx, `
|
if _, err := db.Exec(ctx, `
|
||||||
INSERT INTO prefix_snapshot_row (snapshot_id, ord, prefix, community_id, source)
|
INSERT INTO prefix_snapshot_row (snapshot_id, ord, prefix, community_id, source)
|
||||||
VALUES ($1::uuid, $2, $3::cidr, $4::uuid, $5)`,
|
VALUES ($1::uuid, $2, $3, $4::uuid, $5)`,
|
||||||
snapID, i, strings.TrimSpace(pr.Prefix), comm, src); err != nil {
|
snapID, i, strings.TrimSpace(pr.Prefix), comm, src); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ protocol direct {
|
|||||||
}
|
}
|
||||||
if _, err := tx.Exec(ctx, `
|
if _, err := tx.Exec(ctx, `
|
||||||
INSERT INTO prefix_snapshot_row (snapshot_id, ord, prefix, community_id, source)
|
INSERT INTO prefix_snapshot_row (snapshot_id, ord, prefix, community_id, source)
|
||||||
VALUES ($1::uuid, 0, '203.0.113.0/24'::cidr, $2::uuid, 'demo'),
|
VALUES ($1::uuid, 0, '203.0.113.0/24', $2::uuid, 'demo'),
|
||||||
($1::uuid, 1, '2001:db8::/32'::cidr, $2::uuid, 'demo')`, snapID, cid); err != nil {
|
($1::uuid, 1, '2001:db8::/32', $2::uuid, 'demo')`, snapID, cid); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := tx.Exec(ctx, `
|
if _, err := tx.Exec(ctx, `
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ type SpeakerPatch struct {
|
|||||||
|
|
||||||
// PrefixRow is one materialized prefix for GET /revisions/.../prefixes.
|
// PrefixRow is one materialized prefix for GET /revisions/.../prefixes.
|
||||||
type PrefixRow struct {
|
type PrefixRow struct {
|
||||||
Prefix string
|
Prefix string `json:"prefix"`
|
||||||
CommunityID *string
|
CommunityID *string `json:"community_id,omitempty"`
|
||||||
Source string
|
Source string `json:"source,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ CREATE TABLE prefix_snapshot (
|
|||||||
CREATE TABLE prefix_snapshot_row (
|
CREATE TABLE prefix_snapshot_row (
|
||||||
snapshot_id UUID NOT NULL REFERENCES prefix_snapshot (id) ON DELETE CASCADE,
|
snapshot_id UUID NOT NULL REFERENCES prefix_snapshot (id) ON DELETE CASCADE,
|
||||||
ord INTEGER NOT NULL,
|
ord INTEGER NOT NULL,
|
||||||
prefix CIDR NOT NULL,
|
prefix TEXT NOT NULL,
|
||||||
community_id UUID REFERENCES bgp_community (id) ON DELETE SET NULL,
|
community_id UUID REFERENCES bgp_community (id) ON DELETE SET NULL,
|
||||||
source TEXT NOT NULL DEFAULT '',
|
source TEXT NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (snapshot_id, ord)
|
PRIMARY KEY (snapshot_id, ord)
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
-- Backfill prefix snapshots from revision_materialized_prefix.
|
-- Backfill prefix snapshots from revision_materialized_prefix.
|
||||||
|
-- prefix_snapshot_row.prefix is TEXT (revision_materialized_prefix.prefix since 000003).
|
||||||
|
|
||||||
|
ALTER TABLE prefix_snapshot_row
|
||||||
|
ALTER COLUMN prefix TYPE TEXT USING prefix::text;
|
||||||
|
|
||||||
WITH new_snaps AS (
|
WITH new_snaps AS (
|
||||||
INSERT INTO prefix_snapshot (id, content_hash)
|
INSERT INTO prefix_snapshot (id, content_hash)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ CREATE TABLE module_prefix_snapshot_row (
|
|||||||
tenant_id UUID NOT NULL,
|
tenant_id UUID NOT NULL,
|
||||||
module_id UUID NOT NULL,
|
module_id UUID NOT NULL,
|
||||||
ord INTEGER NOT NULL,
|
ord INTEGER NOT NULL,
|
||||||
prefix CIDR NOT NULL,
|
prefix TEXT NOT NULL,
|
||||||
community_id UUID,
|
community_id UUID,
|
||||||
source TEXT NOT NULL DEFAULT '',
|
source TEXT NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (tenant_id, module_id, ord),
|
PRIMARY KEY (tenant_id, module_id, ord),
|
||||||
@@ -10,16 +10,37 @@ CREATE TABLE module_prefix_snapshot_row (
|
|||||||
REFERENCES module_prefix_snapshot (tenant_id, module_id) ON DELETE CASCADE
|
REFERENCES module_prefix_snapshot (tenant_id, module_id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- prefixes_json from Go json.Marshal(PrefixRow) used "Prefix"/"CommunityID"/"Source" before json tags.
|
||||||
INSERT INTO module_prefix_snapshot_row (tenant_id, module_id, ord, prefix, community_id, source)
|
INSERT INTO module_prefix_snapshot_row (tenant_id, module_id, ord, prefix, community_id, source)
|
||||||
SELECT mps.tenant_id,
|
SELECT tenant_id,
|
||||||
mps.module_id,
|
module_id,
|
||||||
(t.ordinality - 1)::int,
|
(row_number() OVER (PARTITION BY tenant_id, module_id ORDER BY ordinality) - 1)::int,
|
||||||
(t.elem->>'prefix')::cidr,
|
prefix,
|
||||||
NULLIF(t.elem->>'community_id', '')::uuid,
|
NULLIF(community_id, '')::uuid,
|
||||||
COALESCE(NULLIF(t.elem->>'source', ''), '')
|
COALESCE(source, '')
|
||||||
FROM module_prefix_snapshot mps
|
FROM (
|
||||||
CROSS JOIN LATERAL jsonb_array_elements(mps.prefixes_json) WITH ORDINALITY AS t(elem, ordinality)
|
SELECT mps.tenant_id,
|
||||||
WHERE jsonb_typeof(mps.prefixes_json) = 'array'
|
mps.module_id,
|
||||||
AND jsonb_array_length(mps.prefixes_json) > 0;
|
t.ordinality,
|
||||||
|
COALESCE(
|
||||||
|
NULLIF(trim(t.elem->>'prefix'), ''),
|
||||||
|
NULLIF(trim(t.elem->>'Prefix'), '')
|
||||||
|
) AS prefix,
|
||||||
|
COALESCE(
|
||||||
|
NULLIF(trim(t.elem->>'community_id'), ''),
|
||||||
|
NULLIF(trim(t.elem->>'CommunityID'), '')
|
||||||
|
) AS community_id,
|
||||||
|
COALESCE(
|
||||||
|
NULLIF(trim(t.elem->>'source'), ''),
|
||||||
|
NULLIF(trim(t.elem->>'Source'), ''),
|
||||||
|
''
|
||||||
|
) AS source
|
||||||
|
FROM module_prefix_snapshot mps
|
||||||
|
CROSS JOIN LATERAL jsonb_array_elements(mps.prefixes_json) WITH ORDINALITY AS t(elem, ordinality)
|
||||||
|
WHERE jsonb_typeof(mps.prefixes_json) = 'array'
|
||||||
|
AND jsonb_array_length(mps.prefixes_json) > 0
|
||||||
|
) parsed
|
||||||
|
WHERE parsed.prefix IS NOT NULL
|
||||||
|
AND trim(parsed.prefix) <> '';
|
||||||
|
|
||||||
ALTER TABLE module_prefix_snapshot DROP COLUMN prefixes_json;
|
ALTER TABLE module_prefix_snapshot DROP COLUMN prefixes_json;
|
||||||
Reference in new issue
Block a user