Skip to content

Commit

Permalink
Merge pull request #119 from RonasIT/fix-prepare-sequence
Browse files Browse the repository at this point in the history
Fix prepare sequence
  • Loading branch information
DenTray committed May 14, 2024
2 parents 6e9658f + d230922 commit 26c2776
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Traits/FixturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public function prepareSequences(array $except = []): void
$sequenceName = str_replace(["nextval('", "'::regclass)"], '', $item->column_default);

return "SELECT setval('{$sequenceName}', (select coalesce(max({$item->column_name}), 1) from " .
"{$item->table_name}), (case when (select max({$item->column_name}) from {$item->table_name}) " .
"{$item->table_schema}.{$item->table_name}), (case when (select max({$item->column_name}) from {$item->table_schema}.{$item->table_name}) " .
"is NULL then false else true end));\n";

}
});

Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/FixturesTraitTest/prepare_sequences/sequences.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SELECT setval('articles_id_seq', (select coalesce(max(id), 1) from articles), (case when (select max(id) from articles) is NULL then false else true end));
SELECT setval('workers_id_seq', (select coalesce(max(id), 1) from workers), (case when (select max(id) from workers) is NULL then false else true end));
SELECT setval('groups_id_seq', (select coalesce(max(id), 1) from groups), (case when (select max(id) from groups) is NULL then false else true end));
SELECT setval('homes_id_seq', (select coalesce(max(id), 1) from homes), (case when (select max(id) from homes) is NULL then false else true end));
SELECT setval('users_id_seq', (select coalesce(max(id), 1) from users), (case when (select max(id) from users) is NULL then false else true end));
SELECT setval('telescope_entries_sequence_seq', (select coalesce(max(sequence), 1) from telescope_entries), (case when (select max(sequence) from telescope_entries) is NULL then false else true end));
SELECT setval('articles_id_seq', (select coalesce(max(id), 1) from public.articles), (case when (select max(id) from public.articles) is NULL then false else true end));
SELECT setval('workers_id_seq', (select coalesce(max(id), 1) from public.workers), (case when (select max(id) from public.workers) is NULL then false else true end));
SELECT setval('groups_id_seq', (select coalesce(max(id), 1) from public.groups), (case when (select max(id) from public.groups) is NULL then false else true end));
SELECT setval('homes_id_seq', (select coalesce(max(id), 1) from public.homes), (case when (select max(id) from public.homes) is NULL then false else true end));
SELECT setval('users_id_seq', (select coalesce(max(id), 1) from public.users), (case when (select max(id) from public.users) is NULL then false else true end));
SELECT setval('telescope_entries_sequence_seq', (select coalesce(max(sequence), 1) from public.telescope_entries), (case when (select max(sequence) from public.telescope_entries) is NULL then false else true end));

0 comments on commit 26c2776

Please sign in to comment.