Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
whats-this
api
Commits
e15228a5
Commit
e15228a5
authored
2 years ago
by
Auri
Browse files
Options
Downloads
Patches
Plain Diff
sql/v1tov2: properly handle directories in path_full_stem
parent
376b9fac
No related branches found
Branches containing commit
No related tags found
1 merge request
!4
Draft: Migrate the database to schema v2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sql/v1tov2.sql
+36
-14
36 additions, 14 deletions
sql/v1tov2.sql
with
36 additions
and
14 deletions
sql/v1tov2.sql
+
36
−
14
View file @
e15228a5
...
...
@@ -44,28 +44,23 @@ CREATE FUNCTION path_normalize(object_path) RETURNS object_path
LANGUAGE
SQL
AS
$$
SELECT
regexp_replace
(
$
1
,
'/+'
,
'/'
,
'g'
);
$$
;
-- Given '/foo/bar.baz.qux', return '/foo/bar'.
-- See bucket.enforce_unique_names and object.enforce_unique_name.
CREATE
FUNCTION
path_full_stem
(
object_path
)
RETURNS
object_path
IMMUTABLE
STRICT
LANGUAGE
SQL
AS
$$
SELECT
split_part
(
path_normalize
(
$
1
),
'.'
,
1
);
$$
;
-- Given '/foo/bar/baz', return '/foo/bar'.
-- Given '/', return '/'.
-- Given 'foo', return ''.
CREATE
FUNCTION
path_directory
(
object_path
)
RETURNS
object_path
-- Given '/foo/bar/baz', return ('/foo/bar', 'baz').
-- Given 'foo', return ('', 'foo').
CREATE
FUNCTION
path_split
(
object_path
,
OUT
head
object_path
,
OUT
tail
object_path
)
RETURNS
record
IMMUTABLE
STRICT
LANGUAGE
plpgsql
AS
$$
DECLARE
l
integer
=
length
(
$
1
);
l
integer
:
=
length
(
$
1
);
i
integer
;
head
object_path
=
''
;
BEGIN
head
:
=
''
;
tail
:
=
$
1
;
FOR
i
IN
REVERSE
l
..
1
LOOP
IF
starts_with
(
substr
(
$
1
,
i
),
'/'
)
THEN
head
:
=
substr
(
$
1
,
0
,
i
+
1
);
tail
:
=
substr
(
$
1
,
i
+
1
);
EXIT
;
END
IF
;
END
LOOP
;
...
...
@@ -73,8 +68,35 @@ CREATE FUNCTION path_directory(object_path) RETURNS object_path
IF
head
!=
''
AND
head
!=
repeat
(
'/'
,
length
(
head
))
THEN
head
:
=
rtrim
(
head
,
'/'
);
END
IF
;
END
$$
;
RETURN
head
;
-- Given '/foo/bar.baz.qux', return '/foo/bar'.
-- Given '/foo/bar.baz/qux.quux', return '/foo/bar.baz/qux'.
-- See bucket.enforce_unique_names and object.enforce_unique_name.
CREATE
FUNCTION
path_full_stem
(
object_path
)
RETURNS
object_path
IMMUTABLE
STRICT
LANGUAGE
plpgsql
-- AS $$SELECT split_part(path_normalize($1), '.', 1);$$;
AS
$$
DECLARE
split
record
=
path_split
(
path_normalize
(
$
1
));
BEGIN
RETURN
split
.
head
||
'/'
||
split_part
(
split
.
tail
,
'.'
,
1
);
END
$$
;
-- Given '/foo/bar/baz', return '/foo/bar'.
-- Given '/', return '/'.
-- Given 'foo', return ''.
CREATE
FUNCTION
path_directory
(
object_path
)
RETURNS
object_path
IMMUTABLE
STRICT
LANGUAGE
plpgsql
AS
$$
DECLARE
split
record
=
path_split
(
$
1
);
BEGIN
RETURN
split
.
head
;
END
$$
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment