-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.0.0 Improved Postgres Sharded ID fields (#47)
* adding a BasePostgresShardGeneratedIDField to suport more fields * add showmigrations database default as all * whoops wrong shards * WIP * WIP * WIP * WIP * use pre_save and add decorator for user * whoops * bump ersion to 1.0.0
- Loading branch information
Showing
19 changed files
with
323 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django_sharding_library.management.commands.showmigrations import Command as ShowMigrationsCommand | ||
|
||
|
||
class Command(ShowMigrationsCommand): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
django_sharding_library/management/commands/showmigrations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.conf import settings | ||
from django.core.management.commands.showmigrations import Command as ShowMigrationsCommand | ||
|
||
from django_sharding_library.exceptions import InvalidShowMigrationsException | ||
|
||
|
||
class Command(ShowMigrationsCommand): | ||
def handle(self, *args, **options): | ||
if not options['database'] or options['database'] == 'all': | ||
databases = self.get_all_but_replica_dbs() | ||
elif options['database'] not in self.get_all_but_replica_dbs(): | ||
raise InvalidShowMigrationsException('You must use showmigrations an existing non-primary DB.') | ||
else: | ||
databases = [options['database']] | ||
|
||
for database in databases: | ||
options['database'] = database | ||
# Writen in green text to stand out from the surrouding headings | ||
if options['verbosity'] >= 1: | ||
self.stdout.write(getattr(self.style, "MIGRATE_SUCCESS", getattr(self.style, "SUCCESS", lambda a: a))("\nDatabase: {}\n").format(database)) | ||
super(Command, self).handle(*args, **options) | ||
|
||
def get_all_but_replica_dbs(self): | ||
return list(filter( | ||
lambda db: not settings.DATABASES[db].get('PRIMARY', None), | ||
settings.DATABASES.keys() | ||
)) | ||
|
||
def add_arguments(self, parser): | ||
super(Command, self).add_arguments(parser) | ||
parser._option_string_actions['--database'].default = None | ||
parser._option_string_actions['--database'].help = u'Nominates a database to synchronize. Defaults to all databases.' | ||
parser._option_string_actions['--database'].choices = ['all'] + self.get_all_but_replica_dbs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.