def test_numeric(self): Numeric(default=decimal.Decimal(1.0)) Numeric(default=None, null=True) with self.assertRaises(ValueError): Numeric(default="hello world") with self.assertRaises(ValueError): Numeric(default=None, null=False)
def test_alter_column_precision(self): price_1 = Numeric(digits=(4, 2)) price_1._meta.name = "price" price_2 = Numeric(digits=(5, 2)) price_2._meta.name = "price" schema: t.List[DiffableTable] = [ DiffableTable( class_name="Ticket", tablename="ticket", columns=[price_1], ) ] schema_snapshot: t.List[DiffableTable] = [ DiffableTable( class_name="Ticket", tablename="ticket", columns=[price_2], ) ] schema_differ = SchemaDiffer( schema=schema, schema_snapshot=schema_snapshot, auto_input="y" ) self.assertTrue(len(schema_differ.alter_columns.statements) == 1) self.assertEqual( schema_differ.alter_columns.statements[0], "manager.alter_column(table_class_name='Ticket', tablename='ticket', column_name='price', params={'digits': (4, 2)}, old_params={'digits': (5, 2)}, column_class=Numeric, old_column_class=Numeric)", # noqa )
class MegaTable(Table): """ A table containing all of the column types, and different column kwargs. """ bigint_col = BigInt() boolean_col = Boolean() bytea_col = Bytea() date_col = Date() foreignkey_col = ForeignKey(SmallTable) integer_col = Integer() interval_col = Interval() json_col = JSON() jsonb_col = JSONB() numeric_col = Numeric(digits=(5, 2)) real_col = Real() double_precision_col = DoublePrecision() smallint_col = SmallInt() text_col = Text() timestamp_col = Timestamp() timestamptz_col = Timestamptz() uuid_col = UUID() varchar_col = Varchar() unique_col = Varchar(unique=True) null_col = Varchar(null=True) not_null_col = Varchar(null=False)
def test_column_type_conversion_float_decimal(self): self._test_migrations( table_snapshots=[[self.table(column)] for column in [ Real(default=1.0), DoublePrecision(default=1.0), Real(default=1.0), Numeric(), Real(default=1.0), ]])
def test_numeric_column(self): self._test_migrations( table_snapshots=[[self.table(column)] for column in [ Numeric(), Numeric(digits=(4, 2)), Numeric(digits=None), Numeric(default=decimal.Decimal("1.2")), Numeric(default=numeric_default), Numeric(null=True, default=None), Numeric(null=False), Numeric(index=True), Numeric(index=False), ]], test_function=lambda x: all([ x.data_type == "numeric", x.is_nullable == "NO", x.column_default == "0", ]), )
class MegaTable(Table): """ A table containing all of the column types, and different column kwargs. """ array_col = Array(Varchar()) bigint_col = BigInt() boolean_col = Boolean() bytea_col = Bytea() date_col = Date() double_precision_col = DoublePrecision() integer_col = Integer() interval_col = Interval() json_col = JSON() jsonb_col = JSONB() numeric_col = Numeric(digits=(5, 2)) real_col = Real() smallint_col = SmallInt() text_col = Text() timestamp_col = Timestamp() timestamptz_col = Timestamptz() uuid_col = UUID() varchar_col = Varchar()
class MyTable(Table): column_a = Numeric() column_b = Numeric(digits=(3, 2))