Skip to content

Commit

Permalink
support maria db
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenlu committed Jan 24, 2024
1 parent 38221c0 commit 05e127d
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions atlas_provider_django/management/commands/atlas-provider-django.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class Dialect(str, Enum):
mysql = "mysql"
mariadb = "mariadb"
sqlite = "sqlite"
postgresql = "postgresql"

Expand Down Expand Up @@ -74,26 +75,41 @@ def has_native_uuid_field(self):
return False


class MockMariaDBDatabaseFeatures(MySQLDatabaseFeatures):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def has_native_uuid_field(self):
return True


# Returns the database connection wrapper for the given dialect.
# Mocks some methods in order to get the sql statements without db connection.
def get_connection_by_dialect(dialect):
conn = None
if dialect == Dialect.sqlite:
conn = Sqlite3DatabaseWrapper({
"ENGINE": "django.db.backends.sqlite3",
}, "sqlite3")
conn.SchemaEditorClass = MockSqliteSchemaEditor
elif dialect == Dialect.postgresql:
conn = PGDatabaseWrapper({
"ENGINE": "django.db.backends.postgresql",
}, "postgresql")
conn.SchemaEditorClass = MockPGDatabaseSchemaEditor
elif dialect == Dialect.mysql:
conn = MySQLDatabaseWrapper({
"ENGINE": "django.db.backends.mysql",
}, "mysql")
conn.SchemaEditorClass = MockMySQLDatabaseSchemaEditor
conn.features = MockMySQLDatabaseFeatures
match dialect:
case Dialect.sqlite:
conn = Sqlite3DatabaseWrapper({
"ENGINE": "django.db.backends.sqlite3",
}, "sqlite3")
conn.SchemaEditorClass = MockSqliteSchemaEditor
case Dialect.postgresql:
conn = PGDatabaseWrapper({
"ENGINE": "django.db.backends.postgresql",
}, "postgresql")
conn.SchemaEditorClass = MockPGDatabaseSchemaEditor
case Dialect.mysql:
conn = MySQLDatabaseWrapper({
"ENGINE": "django.db.backends.mysql",
}, "mysql")
conn.SchemaEditorClass = MockMySQLDatabaseSchemaEditor
conn.features = MockMySQLDatabaseFeatures(conn)
case Dialect.mariadb:
conn = MySQLDatabaseWrapper({
"ENGINE": "django.db.backends.mysql",
}, "mysql")
conn.SchemaEditorClass = MockMySQLDatabaseSchemaEditor
conn.features = MockMariaDBDatabaseFeatures(conn)
return conn


Expand Down

0 comments on commit 05e127d

Please sign in to comment.