Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for roles. #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions migra/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"collations",
"rlspolicies",
"triggers",
"roles",
"memberships",
]
PK = "PRIMARY KEY"

Expand Down
9 changes: 8 additions & 1 deletion migra/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def parse_args(args):
default=False,
help="Also output privilege differences (ie. grant/revoke statements)",
)
parser.add_argument(
"--with-roles",
dest="with_roles",
action="store_true",
default=False,
help='Also output "create/drop role" statements.',
)
parser.add_argument(
"--force-utf8",
dest="force_utf8",
Expand Down Expand Up @@ -75,7 +82,7 @@ def run(args, out=None, err=None):
if args.create_extensions_only:
m.add_extension_changes(drops=False)
else:
m.add_all_changes(privileges=args.with_privileges)
m.add_all_changes(privileges=args.with_privileges, roles=args.with_roles)
try:
if m.statements:
if args.force_utf8:
Expand Down
13 changes: 10 additions & 3 deletions migra/migra.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import unicode_literals

from sqlbag import raw_execute

from schemainspect import DBInspector, get_inspector
from sqlbag import raw_execute

from .changes import Changes
from .statements import Statements
Expand Down Expand Up @@ -62,7 +61,13 @@ def add_extension_changes(self, creates=True, drops=True):
if drops:
self.add(self.changes.extensions(drops_only=True))

def add_all_changes(self, privileges=False):
def add_all_changes(self, privileges=False, roles=False):
if roles:
if privileges:
self.add(self.changes.memberships(drops_only=True))
self.add(self.changes.roles(drops_only=True))
self.add(self.changes.roles(creations_only=True))

self.add(self.changes.schemas(creations_only=True))

self.add(self.changes.extensions(creations_only=True))
Expand All @@ -87,6 +92,8 @@ def add_all_changes(self, privileges=False):
self.add(self.changes.non_pk_constraints(creations_only=True))
if privileges:
self.add(self.changes.privileges(creations_only=True))
if roles:
self.add(self.changes.memberships(creations_only=True))
self.add(self.changes.rlspolicies(creations_only=True))
self.add(self.changes.triggers(creations_only=True))
self.add(self.changes.collations(drops_only=True))
Expand Down