From 3a83205e70ff36d9a09370eb33f37a55eed3f0c0 Mon Sep 17 00:00:00 2001 From: Bedram Tamang Date: Thu, 9 Jul 2026 11:30:20 -0700 Subject: [PATCH] chore: remove deleted masoniteorm.backup files Remove five stale files under masoniteorm.backup/ that were deleted from the working tree: config.py, config/database.py, factories/Factory.py, factories/__init__.py, and schema/Schema.py. --- .../masoniteorm.backup/config.py | 114 ------ .../masoniteorm.backup/config/database.py | 37 -- .../masoniteorm.backup/factories/Factory.py | 110 ------ .../masoniteorm.backup/factories/__init__.py | 1 - .../masoniteorm.backup/schema/Schema.py | 335 ------------------ 5 files changed, 597 deletions(-) delete mode 100644 fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config.py delete mode 100644 fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config/database.py delete mode 100644 fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/Factory.py delete mode 100644 fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/__init__.py delete mode 100644 fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/schema/Schema.py diff --git a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config.py b/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config.py deleted file mode 100644 index 2a5228ff..00000000 --- a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config.py +++ /dev/null @@ -1,114 +0,0 @@ -import os -import pydoc -import urllib.parse as urlparse - -from .exceptions import ConfigurationNotFound, InvalidUrlConfiguration - - -def load_config(config_path=None): - """Load ORM configuration from given configuration path (dotted or not). - If no path is provided: - 1. try to load from DB_CONFIG_PATH environment variable - 2. else try to load from default config_path: config/database - """ - selected_config_path = os.getenv("DB_CONFIG_PATH", config_path) or "config/database" - - os.environ["DB_CONFIG_PATH"] = selected_config_path - - # format path as python module if needed - selected_config_path = selected_config_path.replace("/", ".").replace("\\", ".").rstrip(".py") - - config_module = pydoc.locate(selected_config_path) - if config_module is None: - raise ConfigurationNotFound(f"ORM configuration file has not been found in {selected_config_path}") - return config_module - - -def db_url(database_url=None, prefix="", options={}, log_queries=False): - """Parse connection configuration from database url format. If no url is provided, - DATABASE_URL environment variable will be used instead. - - Reference: Code adapted from https://github.com/jacobian/dj-database-url - """ - - url = database_url or os.getenv("DATABASE_URL") - if not url: - raise InvalidUrlConfiguration("Database url is empty !") - - # Register database schemes in URLs. - urlparse.uses_netloc.append("postgres") - urlparse.uses_netloc.append("postgresql") - urlparse.uses_netloc.append("pgsql") - urlparse.uses_netloc.append("postgis") - urlparse.uses_netloc.append("mysql") - urlparse.uses_netloc.append("mysql2") - urlparse.uses_netloc.append("mysqlgis") - urlparse.uses_netloc.append("mssql") - urlparse.uses_netloc.append("sqlite") - - DRIVERS_MAP = { - "postgres": "postgres", - "postgresql": "postgres", - "pgsql": "postgres", - "postgis": "postgres", - "mysql": "mysql", - "mysql2": "mysql", - "mysqlgis": "mysql", - "mysql-connector": "mysql", - "mssql": "mssql", - "sqlite": "sqlite", - } - - # this is a special case, because if we pass this URL into - # urlparse, urlparse will choke trying to interpret "memory" - # as a port number - if url in ["sqlite://:memory:", "sqlite://memory"]: - driver = DRIVERS_MAP["sqlite"] - path = ":memory:" - # otherwise parse the url as normal - else: - url = urlparse.urlparse(url) - # remove query string from path (not parsed for now) - path = url.path[1:] - if "?" in path and not url.query: - path, _ = path.split("?", 2) - - # if we are using sqlite and we have no path, then assume we - # want an in-memory database (this is the behaviour of sqlalchemy) - if url.scheme == "sqlite" and path == "": - path = ":memory:" - - # handle postgres percent-encoded paths. - hostname = url.hostname or "" - if "%2f" in hostname.lower(): - # Switch to url.netloc to avoid lower cased paths - hostname = url.netloc - if "@" in hostname: - hostname = hostname.rsplit("@", 1)[1] - if ":" in hostname: - hostname = hostname.split(":", 1)[0] - hostname = hostname.replace("%2f", "/").replace("%2F", "/") - - # lookup specified driver - driver = DRIVERS_MAP[url.scheme] - port = str(url.port) if url.port and driver in [DRIVERS_MAP["mssql"]] else url.port - - # build final configuration - config = { - "driver": driver, - "database": urlparse.unquote(path or ""), - "prefix": prefix, - "options": options, - "log_queries": log_queries, - } - - if driver != DRIVERS_MAP["sqlite"]: - config.update( - { - "user": urlparse.unquote(url.username or ""), - "password": urlparse.unquote(url.password or ""), - "host": hostname, - "port": port or "", - } - ) - return config diff --git a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config/database.py b/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config/database.py deleted file mode 100644 index 353dd3b0..00000000 --- a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/config/database.py +++ /dev/null @@ -1,37 +0,0 @@ -import os - -DATABASES = { - "default": "mysql", - "mysql": { - "host": "127.0.0.1", - "driver": "mysql", - "database": os.getenv("DB_DATABASE"), - "user": "root", - "password": "", - "port": 3306, - "log_queries": False, - "options": { - # - }, - }, - "postgres": { - "host": "127.0.0.1", - "driver": "postgres", - "database": "masonite", - "user": "root", - "password": "", - "port": 5432, - "log_queries": False, - "options": { - # - }, - }, - "sqlite": { - "driver": "sqlite", - "database": "masonite.sqlite3", - }, -} - -MIGRATION_PATH = "databases/migrations" - -SEEDER_PATH = "databases/seeders" diff --git a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/Factory.py b/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/Factory.py deleted file mode 100644 index aed8fcdb..00000000 --- a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/Factory.py +++ /dev/null @@ -1,110 +0,0 @@ -import random - - -class Factory: - _factories = {} - _after_creates = {} - _faker = None - - @property - def faker(self): - try: - from faker import Faker - except ImportError: - raise ImportError("Could not find the 'faker' library. Run 'pip install faker' to fix this.") - - if not Factory._faker: - Factory._faker = Faker() - random.seed() - Factory._faker.seed_instance(random.randint(1, 10000)) - - return Factory._faker - - def __init__(self, model, number=1): - self.model = model - self.number = number - - def make(self, dictionary=None, name="default"): - if dictionary is None: - dictionary = {} - - if self.number == 1 and not isinstance(dictionary, list): - called = self._factories[self.model][name](self.faker) - called.update(dictionary) - model = self.model.hydrate(called) - self.run_after_creates(model) - return model - elif isinstance(dictionary, list): - results = [] - for index in range(0, len(dictionary)): - called = self._factories[self.model][name](self.faker) - called.update(dictionary) - results.append(called) - models = self.model.hydrate(results) - for model in models: - self.run_after_creates(model) - return models - - else: - results = [] - for index in range(0, self.number): - called = self._factories[self.model][name](self.faker) - called.update(dictionary) - results.append(called) - models = self.model.hydrate(results) - for model in models: - self.run_after_creates(model) - return models - - def create(self, dictionary=None, name="default"): - if dictionary is None: - dictionary = {} - - if self.number == 1 and not isinstance(dictionary, list): - called = self._factories[self.model][name](self.faker) - called.update(dictionary) - model = self.model.create(called) - self.run_after_creates(model) - return model - elif isinstance(dictionary, list): - results = [] - for index in range(0, len(dictionary)): - called = self._factories[self.model][name](self.faker) - called.update(dictionary) - results.append(called) - - models = self.model.create(results) - for model in models: - self.run_after_creates(model) - return models - else: - full_collection = [] - for index in range(0, self.number): - called = self._factories[self.model][name](self.faker) - called.update(dictionary) - full_collection.append(called) - model = self.model.create(called) - self.run_after_creates(model) - - return self.model.hydrate(full_collection) - - @classmethod - def register(cls, model, call, name="default"): - if model not in cls._factories: - cls._factories[model] = {name: call} - else: - cls._factories[model][name] = call - - @classmethod - def after_creating(cls, model, call, name="default"): - if model not in cls._after_creates: - cls._after_creates[model] = {name: call} - else: - cls._after_creates[model][name] = call - - def run_after_creates(self, model): - if self.model not in self._after_creates: - return model - - for name, callback in self._after_creates[self.model].items(): - callback(model, self.faker) diff --git a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/__init__.py b/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/__init__.py deleted file mode 100644 index c54268d4..00000000 --- a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/factories/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .Factory import Factory diff --git a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/schema/Schema.py b/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/schema/Schema.py deleted file mode 100644 index 3779ffcf..00000000 --- a/fastapi_startkit/src/fastapi_startkit/masoniteorm.backup/schema/Schema.py +++ /dev/null @@ -1,335 +0,0 @@ -from ..config import load_config -from ..exceptions import ConnectionNotRegistered -from .Blueprint import Blueprint -from .Table import Table -from .TableDiff import TableDiff - - -class Schema: - _default_string_length = "255" - _type_hints_map = { - "string": str, - "char": str, - "big_increments": int, - "integer": int, - "big_integer": int, - "tiny_integer": int, - "small_integer": int, - "medium_integer": int, - "integer_unsigned": int, - "big_integer_unsigned": int, - "tiny_integer_unsigned": int, - "small_integer_unsigned": int, - "medium_integer_unsigned": int, - "increments": int, - "uuid": str, - "binary": bytes, - "boolean": bool, - "decimal": float, - "double": float, - "enum": str, - "text": str, - "float": float, - "geometry": str, # ? - "json": dict, - "jsonb": bytes, - "inet": str, - "cidr": str, - "macaddr": str, - "long_text": str, - "point": str, # ? - "time": str, # or pendulum.DateTime - "timestamp": str, # or pendulum.DateTime - "date": str, # or pendulum.DateTime - "year": str, - "datetime": str, # or pendulum.DateTime - "tiny_increments": int, - "unsigned": int, - "unsigned_integer": int, - } - - def __init__( - self, - dry=False, - connection="default", - connection_class=None, - platform=None, - grammar=None, - connection_details=None, - schema=None, - config_path=None, - ): - self._dry = dry - self.connection = connection - self.connection_class = connection_class - self._connection = None - self.grammar = grammar - self.platform = platform - self.connection_details = connection_details or {} - self._blueprint = None - self._sql = None - self.schema = schema - self.config_path = config_path - - if not self.connection_class: - self.on(self.connection) - - if not self.platform: - self.platform = self.connection_class.get_default_platform() - - def on(self, connection_key): - """Change the connection from the default connection - - Arguments: - connection {string} -- A connection string like 'mysql' or 'mssql'. - It will be made with the connection factory. - - Returns: - cls - """ - resolver = load_config(config_path=self.config_path).DB - self.connection_details = resolver.get_connection_details() - if connection_key == "default": - self.connection = self.connection_details.get("default") - else: - self.connection = connection_key - - connection_detail = self.connection_details.get(self.connection) - if connection_detail: - self._connection_driver = connection_detail.get("driver") - else: - raise ConnectionNotRegistered(f"Could not find the '{connection_key}' connection details") - - self.connection_class = resolver._drivers.get(self._connection_driver) - - return self - - def dry(self): - """Whether the query should be executed. (default: {False}) - - Returns: - self - """ - self._dry = True - return self - - async def create(self, table): - """Sets the table and returns the blueprint. - - This should be used as a context manager. - - Arguments: - table {string} -- The name of a table like 'users' - - Returns: - masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object. - """ - self._table = table - - self._blueprint = Blueprint( - self.grammar, - connection=await self.new_connection(), - table=Table(table), - action="create", - platform=self.platform, - schema=self.schema, - default_string_length=self._default_string_length, - dry=self._dry, - ) - - return self._blueprint - - async def create_table_if_not_exists(self, table): - self._table = table - - self._blueprint = Blueprint( - self.grammar, - connection=await self.new_connection(), - table=Table(table), - action="create_table_if_not_exists", - platform=self.platform, - schema=self.schema, - default_string_length=self._default_string_length, - dry=self._dry, - ) - - return self._blueprint - - async def table(self, table): - """Sets the table and returns the blueprint. - - This should be used as a context manager. - - Arguments: - table {string} -- The name of a table like 'users' - - Returns: - masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object. - """ - self._table = table - - self._blueprint = Blueprint( - self.grammar, - connection=await self.new_connection(), - table=TableDiff(table), - action="alter", - platform=self.platform, - schema=self.schema, - default_string_length=self._default_string_length, - dry=self._dry, - ) - - return self._blueprint - - def get_connection_information(self): - return { - "host": self.connection_details.get(self.connection, {}).get("host"), - "database": self.connection_details.get(self.connection, {}).get("database"), - "user": self.connection_details.get(self.connection, {}).get("user"), - "port": self.connection_details.get(self.connection, {}).get("port"), - "password": self.connection_details.get(self.connection, {}).get("password"), - "prefix": self.connection_details.get(self.connection, {}).get("prefix"), - "options": self.connection_details.get(self.connection, {}).get("options", {}), - "full_details": self.connection_details.get(self.connection), - } - - async def new_connection(self): - if self._dry: - return - - # TODO: review - if not self._connection: - connection_details = self.get_connection_information().get("full_details") - self._connection = self.connection_class(connection_details=connection_details, name=self.connection) - if hasattr(self._connection, "set_schema"): - self._connection.set_schema(self.schema) - await self._connection.make_connection() - - return self._connection - - async def has_column(self, table, column, query_only=False): - """Checks if the a table has a specific column - - Arguments: - table {string} -- The name of a table like 'users' - - Returns: - masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object. - """ - sql = self.platform().compile_column_exists(table, column) - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - async def get_columns(self, table, dict=True): - table = self.platform().get_current_schema(await self.new_connection(), table, schema=self.get_schema()) - result = {} - if dict: - for column in table.get_added_columns().items(): - result.update({column[0]: column[1]}) - return result - else: - return table.get_added_columns().items() - - @classmethod - def set_default_string_length(cls, length): - cls._default_string_length = length - return cls - - async def drop_table(self, table, query_only=False): - sql = self.platform().compile_drop_table(table) - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - def drop(self, *args, **kwargs): - return self.drop_table(*args, **kwargs) - - async def drop_table_if_exists(self, table, exists=False, query_only=False): - sql = self.platform().compile_drop_table_if_exists(table) - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - async def rename(self, table, new_name): - sql = self.platform().compile_rename_table(table, new_name) - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - async def truncate(self, table, foreign_keys=False): - sql = self.platform().compile_truncate(table, foreign_keys=foreign_keys) - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - def get_schema(self): - """Gets the schema set on the migration class""" - return self.schema or self.get_connection_information().get("full_details").get("schema") - - async def get_all_tables(self): - """Gets all tables in the database""" - sql = self.platform().compile_get_all_tables( - database=self.get_connection_information().get("database"), - schema=self.get_schema(), - ) - - if self._dry: - self._sql = sql - return sql - - result = await (await self.new_connection()).query(sql, ()) - - return list(map(lambda t: list(t.values())[0], result)) if result else [] - - async def has_table(self, table, query_only=False): - """Checks if the a database has a specific table - Arguments: - table {string} -- The name of a table like 'users' - Returns: - masoniteorm.blueprint.Blueprint -- The Masonite ORM blueprint object. - """ - sql = self.platform().compile_table_exists( - table, - database=self.get_connection_information().get("database"), - schema=self.get_schema(), - ) - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - async def enable_foreign_key_constraints(self): - sql = self.platform().enable_foreign_key_constraints() - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ())) - - async def disable_foreign_key_constraints(self): - sql = self.platform().disable_foreign_key_constraints() - - if self._dry: - self._sql = sql - return sql - - return bool(await (await self.new_connection()).query(sql, ()))