noc.core.migration.db

Module Contents

noc.core.migration.db.logger
class noc.core.migration.db.DB

Bases: object

PostgreSQL database migration operations

MAX_NAME_LENGTH = 63
static quote_name(name)
has_table(self, table_name)
create_table(self, table_name, fields)
delete_table(self, table_name, cascade=True)
has_column(self, table_name, name)

Check if table has column :param table_name: Table name :param name: Column name :return: True, if table has column, False otherwise

add_column(self, table_name, name, field)
delete_column(self, table_name, field_name)
rename_column(self, table_name, old, new)
execute(self, sql, params=None)

Executes the given SQL statement, with optional parameters :param sql: SQL statement :param params: List of positional parameters :return:

create_index(self, table_name, column_names, unique=False)
mock_model(self, model_name, db_table, pk_field_name='id', pk_field_type=AutoField, pk_field_args=None, pk_field_kwargs=None)
column_sql(self, table_name, field_name, field, with_name=True, field_prepared=False)

Create the SQL snippet for a column.

_foreign_key_sql(self, from_table_name, from_column_name, to_table_name, to_column_name)

Generates a full SQL statement to add a foreign key constraint

execute_deferred_sql(self)
_sql_indexes_for_field(self, model, field)

Return the CREATE INDEX SQL statements for a single model field

Parameters:
  • model
  • field
Returns:

noc.core.migration.db.db