Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dollar in layer name #8241

Merged
merged 12 commits into from
Dec 10, 2024
11 changes: 11 additions & 0 deletions conf/evolutions/125-allow-dollar-in-layer-names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
START TRANSACTION;

do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 124, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql;


ALTER TABLE webknossos.annotation_layers DROP CONSTRAINT IF EXISTS annotation_layers_name_check;
ALTER TABLE webknossos.annotation_layers ADD CONSTRAINT annotation_layers_name_check CHECK (name ~* '^[A-Za-z0-9\-_\.\$]+$');

UPDATE webknossos.releaseInformation SET schemaVersion = 125;

COMMIT TRANSACTION;
11 changes: 11 additions & 0 deletions conf/evolutions/reversions/125-allow-dollar-in-layer-names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
START TRANSACTION;

-- This reversion might take a while because it needs to search in all annotation layer names for '$' and replace it with ''
do $$ begin ASSERT (select schemaVersion from webknossos.releaseInformation) = 125, 'Previous schema version mismatch'; end; $$ LANGUAGE plpgsql;

UPDATE webknossos.annotation_layers SET name = regexp_replace(name, '\$', '', 'g') WHERE name ~* '\$';
daniel-wer marked this conversation as resolved.
Show resolved Hide resolved

ALTER TABLE webknossos.annotation_layers DROP CONSTRAINT IF EXISTS annotation_layers_name_check;
ALTER TABLE webknossos.annotation_layers ADD CONSTRAINT annotation_layers_name_check CHECK (name ~* '^[A-Za-z0-9\-_\.]+$');

daniel-wer marked this conversation as resolved.
Show resolved Hide resolved
COMMIT TRANSACTION;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function checkLayerNameForInvalidCharacters(readableLayerName: string): V
message: messages["tracing.volume_layer_name_starts_with_dot"],
};
}
const uriSafeCharactersRegex = /[0-9a-zA-Z-._]+/g;
const uriSafeCharactersRegex = /[0-9a-zA-Z-._$]+/g;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly you found that these characters don't necessarily have to be url safe, right? If so, maybe rename to validLayerNameCharactersRegex or so instead.

// Removing all URISaveCharacters from readableLayerName. The leftover chars are all invalid.
const allInvalidChars = readableLayerName.replace(uriSafeCharactersRegex, "");
const allUniqueInvalidCharsAsSet = new Set(allInvalidChars);
Expand Down
4 changes: 2 additions & 2 deletions tools/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE TABLE webknossos.releaseInformation (
schemaVersion BIGINT NOT NULL
);

INSERT INTO webknossos.releaseInformation(schemaVersion) values(124);
INSERT INTO webknossos.releaseInformation(schemaVersion) values(125);
COMMIT TRANSACTION;


Expand Down Expand Up @@ -56,7 +56,7 @@ CREATE TABLE webknossos.annotation_layers(
_annotation CHAR(24) NOT NULL,
tracingId CHAR(36) NOT NULL UNIQUE,
typ webknossos.ANNOTATION_LAYER_TYPE NOT NULL,
name VARCHAR(256) NOT NULL CHECK (name ~* '^[A-Za-z0-9\-_\.]+$'),
name VARCHAR(256) NOT NULL CHECK (name ~* '^[A-Za-z0-9\-_\.\$]+$'),
statistics JSONB NOT NULL,
UNIQUE (name, _annotation),
PRIMARY KEY (_annotation, tracingId),
Expand Down