Open m0nhawk opened 9 months ago
Found the same thing! When I was going through he performance optimization PR, I was looking where permissions were created (sec_permission) and noticed that there's 2 sequences (this is found in my pgAdmin for my local env):
sec_permission_id_seq
sec_permission_sequence
(These are the two that you pionted out above).
Where'd they come from? To find out, I looked at postgres migration scripts and searched for each:
sec_permission_sequence
was introduced in migration V1.0.0.9__shrio_security.sql
sec_permission_id_seq
was introduced in migration V1.0.11.0_data-cojhort-analysis-permission.
I'm not sure why the latter introduced a new sequence, but probably a developer error where they didn't see it.
But the sec_permission_id_seq
is the one used in our JPA entity definition, so that's the only one that matters.
It's unfortunate about that because the naming convention that is used isn't the one we would want: the sequence name should be {table}_sequence (or _seq is also used).
I think the fix here is to introduce a migration that will drop the un-used sequence.
@chrisknoll @m0nhawk the migration to fix this could be something like:
SELECT setval('sec_permission_sequence', (select max(id)+1 from sec_permission), false);
DROP SEQUENCE ohdsi.sec_permission_seq;
Right, but dropping sec_permission_id_seq
, but also updating the Entity definition to use the sec_permission_sequence. I think those 2 steps would do it.
I noticed something strange in the DB definitions:
In here there is a table definition (I am using Postgres):
But, around the code I see a lot of INSERT statements for other sequence for this table from here, e.g.:
Is there any reason there are two sequences for the same thing?