Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Nullachtvierzehn UG (haftungsbeschränkt)
Sqitch Utils
Commits
2a687a29
Commit
2a687a29
authored
3 years ago
by
Timo Stolz
Browse files
Options
Download
Email Patches
Plain Diff
auto-increase updated_at columns
parents
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
defaults.sql
+5
-0
defaults.sql
deploy/increase-updated-at.sql
+19
-0
deploy/increase-updated-at.sql
revert/increase-updated-at.sql
+9
-0
revert/increase-updated-at.sql
sqitch.conf
+4
-0
sqitch.conf
sqitch.plan
+5
-0
sqitch.plan
tests/increase-updatet-at.sql
+29
-0
tests/increase-updatet-at.sql
verify/increase-updated-at.sql
+7
-0
verify/increase-updated-at.sql
with
78 additions
and
0 deletions
+78
-0
defaults.sql
0 → 100644
View file @
2a687a29
\
if
:{
?
utils_schema
}
\
else
\
set
utils_schema
public
\
endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
deploy/increase-updated-at.sql
0 → 100644
View file @
2a687a29
-- Deploy 0814-utils:increase-updated-at to pg
BEGIN
;
\
ir
..
/
defaults
.
sql
create
schema
if
not
exists
:
"utils_schema"
;
create
or
replace
function
:
"utils_schema"
.
auto_increase_updated_at
()
returns
trigger
as
$$
begin
if
new
is
distinct
from
old
and
new
.
updated_at
<=
old
.
updated_at
then
new
.
updated_at
:
=
current_timestamp
;
end
if
;
return
new
;
end
;
$$
language
plpgsql
volatile
;
COMMIT
;
This diff is collapsed.
Click to expand it.
revert/increase-updated-at.sql
0 → 100644
View file @
2a687a29
-- Revert 0814-utils:increase-updated-at from pg
BEGIN
;
\
ir
..
/
defaults
.
sql
drop
function
:
"utils_schema"
.
auto_increase_updated_at
();
COMMIT
;
This diff is collapsed.
Click to expand it.
sqitch.conf
0 → 100644
View file @
2a687a29
[
core
]
engine
=
pg
plan_file
= ./
sqitch
.
plan
# top_dir = .
This diff is collapsed.
Click to expand it.
sqitch.plan
0 → 100644
View file @
2a687a29
%syntax-version=1.0.0
%project=0814-utils
%uri=https://gitlab.nullachtvierzehn.de/0814/sqitch-utils
increase-updated-at 2022-03-08T14:05:05Z Timo Stolz <timo.stolz@nullachtvierzehn.de> # automatically increase updated at
This diff is collapsed.
Click to expand it.
tests/increase-updatet-at.sql
0 → 100644
View file @
2a687a29
begin
;
\
ir
..
/
defaults
.
sql
create
extension
if
not
exists
pgtap
;
select
plan
(
2
);
create
table
test_10ad83aa_9eeb_11ec_8549_7bbf46bf41a7
(
id
integer
primary
key
,
updatable
varchar
,
updated_at
timestamptz
not
null
default
current_timestamp
);
create
trigger
t900_auto_increase_updated_at
before
update
on
test_10ad83aa_9eeb_11ec_8549_7bbf46bf41a7
for
each
row
execute
function
:
"utils_schema"
.
auto_increase_updated_at
();
insert
into
test_10ad83aa_9eeb_11ec_8549_7bbf46bf41a7
values
(
1
,
'initial'
,
'2000-01-01 00:00:00'
);
select
is
(
updated_at
,
'2000-01-01 00:00:00'
)
from
test_10ad83aa_9eeb_11ec_8549_7bbf46bf41a7
;
update
test_10ad83aa_9eeb_11ec_8549_7bbf46bf41a7
set
updatable
=
'updated'
;
select
is
(
updated_at
,
current_timestamp
)
from
test_10ad83aa_9eeb_11ec_8549_7bbf46bf41a7
;
rollback
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
verify/increase-updated-at.sql
0 → 100644
View file @
2a687a29
-- Verify 0814-utils:increase-updated-at on pg
BEGIN
;
-- XXX Add verifications here.
ROLLBACK
;
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help