Skip to content

Commit

Permalink
Finish feature/OP-461
Browse files Browse the repository at this point in the history
OP-461: added migration script to apply roles for admin for that module
  • Loading branch information
dragos-dobre authored Nov 26, 2021
2 parents c8855e4 + dc8b254 commit 6e0203a
Showing 1 changed file with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import logging

from django.db import migrations

logger = logging.getLogger(__name__)


MIGRATION_SQL = """
/* Contribution plan and bundle*/
DECLARE @SystemRole INT
SELECT @SystemRole = role.RoleID from tblRole role where IsSystem=256;
/* Contribution plan bundle*/
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151101)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151101, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151102)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151102, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151103)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151103, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151104)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151104, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151106)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151106, CURRENT_TIMESTAMP)
END
/* Contribution plan */
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151201)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151201, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151202)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151202, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151203)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151203, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151204)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151204, CURRENT_TIMESTAMP)
END
IF NOT EXISTS (SELECT * FROM [tblRoleRight] WHERE [RoleID] = @SystemRole AND [RightID] = 151206)
BEGIN
INSERT [dbo].[tblRoleRight] ([RoleID], [RightID], [ValidityFrom])
VALUES (@SystemRole, 151206, CURRENT_TIMESTAMP)
END
"""


class Migration(migrations.Migration):
dependencies = [
('contribution_plan', '0008_historicalpaymentplan_paymentplan')
]

operations = [
migrations.RunSQL(MIGRATION_SQL)
]

0 comments on commit 6e0203a

Please sign in to comment.