Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mentat-test
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
mentat-test
Commits
a99f07d9
Commit
a99f07d9
authored
3 years ago
by
Rajmund Hruška
Browse files
Options
Downloads
Plain Diff
Merge branch 'hruska-bugfix-#7220-mail_to' into devel
parents
e3d89271
572cda28
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/hawat/migrations/versions/4a172cd00ef0_clean_mail_to_and_add_not_null_.py
+96
-0
96 additions, 0 deletions
.../versions/4a172cd00ef0_clean_mail_to_and_add_not_null_.py
lib/mentat/datatype/sqldb.py
+4
-4
4 additions, 4 deletions
lib/mentat/datatype/sqldb.py
with
100 additions
and
4 deletions
lib/hawat/migrations/versions/4a172cd00ef0_clean_mail_to_and_add_not_null_.py
0 → 100644
+
96
−
0
View file @
a99f07d9
"""
Clean mail_to, emails and add not null constraints
Revision ID: 4a172cd00ef0
Revises: c2b4c2af6196
Create Date: 2021-07-20 10:46:04.138409
"""
from
alembic
import
op
# revision identifiers, used by Alembic.
revision
=
'
4a172cd00ef0
'
down_revision
=
'
c2b4c2af6196
'
branch_labels
=
None
depends_on
=
None
def
upgrade
():
op
.
execute
(
"""
CREATE OR REPLACE FUNCTION alembic_4a172cd00ef0_trim_array(character varying[])
RETURNS character varying[]
AS
$$
DECLARE
arr ALIAS FOR $1;
element character varying;
retVal character varying[];
BEGIN
FOREACH element IN ARRAY arr
LOOP
retVal := array_append(retVal, trim(element)::varchar);
END LOOP;
RETURN retVal;
END;
$$
LANGUAGE plpgsql
STABLE
RETURNS NULL ON NULL INPUT;
"""
)
op
.
execute
(
"""
CREATE OR REPLACE FUNCTION alembic_4a172cd00ef0_split_strings(character varying[])
RETURNS character varying[]
AS
$$
DECLARE
arr ALIAS FOR $1;
element character varying;
retVal character varying[];
BEGIN
FOREACH element IN ARRAY arr
LOOP
retVal := retVal || alembic_4a172cd00ef0_trim_array(string_to_array(element,
'
,
'
)::varchar[]);
END LOOP;
RETURN retVal;
END;
$$
LANGUAGE plpgsql
STABLE
RETURNS NULL ON NULL INPUT;
"""
)
op
.
execute
(
"
UPDATE reports_events SET mail_to = alembic_4a172cd00ef0_trim_array(mail_to)
"
)
op
.
execute
(
"
UPDATE reports_events SET mail_to = ARRAY[]::varchar[] WHERE mail_to IS NULL OR mail_to =
'
{None}
'"
)
op
.
execute
(
"
ALTER TABLE reports_events ALTER COLUMN mail_to SET NOT NULL
"
)
op
.
execute
(
"
UPDATE settings_reporting SET emails = alembic_4a172cd00ef0_split_strings(emails)
"
)
op
.
execute
(
"
UPDATE settings_reporting SET emails = ARRAY[]::varchar[] WHERE emails IS NULL
"
)
op
.
execute
(
"
ALTER TABLE settings_reporting ALTER COLUMN emails SET NOT NULL
"
)
op
.
execute
(
"
DROP FUNCTION alembic_4a172cd00ef0_split_strings(character varying[])
"
)
op
.
execute
(
"
DROP FUNCTION alembic_4a172cd00ef0_trim_array(character varying[])
"
)
def
downgrade
():
op
.
execute
(
"
ALTER TABLE reports_events ALTER COLUMN mail_to DROP NOT NULL
"
)
op
.
execute
(
"
ALTER TABLE settings_reporting ALTER COLUMN emails DROP NOT NULL
"
)
This diff is collapsed.
Click to expand it.
lib/mentat/datatype/sqldb.py
+
4
−
4
View file @
a99f07d9
...
...
@@ -585,7 +585,7 @@ class SettingsReportingModel(MODEL): # pylint: disable=locally-disabled,too-few
group_id
=
sqlalchemy
.
Column
(
sqlalchemy
.
Integer
,
sqlalchemy
.
ForeignKey
(
'
groups.id
'
,
onupdate
=
"
CASCADE
"
,
ondelete
=
"
CASCADE
"
),
nullable
=
False
)
group
=
sqlalchemy
.
orm
.
relationship
(
'
GroupModel
'
,
back_populates
=
'
settings_rep
'
)
emails
=
sqlalchemy
.
Column
(
sqlalchemy
.
dialects
.
postgresql
.
ARRAY
(
sqlalchemy
.
String
,
dimensions
=
1
))
emails
=
sqlalchemy
.
Column
(
sqlalchemy
.
dialects
.
postgresql
.
ARRAY
(
sqlalchemy
.
String
,
dimensions
=
1
)
,
default
=
[],
nullable
=
False
)
mode
=
sqlalchemy
.
Column
(
sqlalchemy
.
Enum
(
*
REPORTING_MODES
,
name
=
'
reporting_modes
'
))
locale
=
sqlalchemy
.
Column
(
sqlalchemy
.
String
)
timezone
=
sqlalchemy
.
Column
(
sqlalchemy
.
String
)
...
...
@@ -603,7 +603,7 @@ class SettingsReportingModel(MODEL): # pylint: disable=locally-disabled,too-few
'
id
'
:
int
(
self
.
id
),
'
createtime
'
:
str
(
self
.
createtime
),
'
group
'
:
str
(
self
.
group
),
'
emails
'
:
[
str
(
x
)
for
x
in
self
.
emails
]
if
self
.
emails
is
not
None
else
None
,
'
emails
'
:
[
str
(
x
)
for
x
in
self
.
emails
],
'
mode
'
:
str
(
self
.
mode
)
if
self
.
mode
is
not
None
else
None
,
'
locale
'
:
str
(
self
.
locale
)
if
self
.
locale
is
not
None
else
None
,
'
timezone
'
:
str
(
self
.
timezone
)
if
self
.
timezone
is
not
None
else
None
,
...
...
@@ -619,7 +619,7 @@ def setrepmodel_from_typeddict(structure, defaults = None):
defaults
=
{}
sqlobj
=
SettingsReportingModel
()
sqlobj
.
emails
=
structure
.
get
(
'
rep_emails
'
,
None
)
sqlobj
.
emails
=
structure
.
get
(
'
rep_emails
'
,
[]
)
sqlobj
.
mode
=
structure
.
get
(
'
rep_mode
'
,
None
)
sqlobj
.
redirect
=
structure
.
get
(
'
rep_redirect
'
,
None
)
...
...
@@ -759,7 +759,7 @@ class EventReportModel(MODEL):
# Number of relapsed events.
evcount_rlp
=
sqlalchemy
.
Column
(
sqlalchemy
.
Integer
)
mail_to
=
sqlalchemy
.
Column
(
sqlalchemy
.
dialects
.
postgresql
.
ARRAY
(
sqlalchemy
.
String
,
dimensions
=
1
))
mail_to
=
sqlalchemy
.
Column
(
sqlalchemy
.
dialects
.
postgresql
.
ARRAY
(
sqlalchemy
.
String
,
dimensions
=
1
)
,
default
=
[],
nullable
=
False
)
mail_dt
=
sqlalchemy
.
Column
(
sqlalchemy
.
DateTime
)
mail_res
=
sqlalchemy
.
Column
(
sqlalchemy
.
String
)
...
...
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