From d868e2fd82213110d19f46d6a4564a66fbdfac45 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:53:34 +0800 Subject: [PATCH 01/16] removed forced primary key assignment for *increments() --- src/masoniteorm/schema/Blueprint.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/masoniteorm/schema/Blueprint.py b/src/masoniteorm/schema/Blueprint.py index 05089501..f6c219d5 100644 --- a/src/masoniteorm/schema/Blueprint.py +++ b/src/masoniteorm/schema/Blueprint.py @@ -161,7 +161,7 @@ def _compile_alter(self): )._compile_create() def increments(self, column, nullable=False): - """Sets a column to be the auto incrementing primary key representation for the table. + """Sets a column to be the auto-incrementing integer. Arguments: column {string} -- The column name. @@ -176,11 +176,10 @@ def increments(self, column, nullable=False): column, "increments", nullable=nullable ) - self.primary(column) return self def tiny_increments(self, column, nullable=False): - """Sets a column to be the auto tiny incrementing primary key representation for the table. + """Sets a column to an auto-increment tiny integer. Arguments: column {string} -- The column name. @@ -195,11 +194,10 @@ def tiny_increments(self, column, nullable=False): column, "tiny_increments", nullable=nullable ) - self.primary(column) return self def id(self, column="id"): - """Sets a column to be the auto-incrementing big integer (8-byte) primary key representation for the table. + """Sets a column to an auto-incrementing big integer. Arguments: column {string} -- The column name. Defaults to "id". @@ -207,7 +205,7 @@ def id(self, column="id"): Returns: self """ - return self.big_increments(column) + return self.big_increments(column).primary() def uuid(self, column, nullable=False, length=36): """Sets a column to be the UUID4 representation for the table. @@ -227,7 +225,7 @@ def uuid(self, column, nullable=False, length=36): return self def big_increments(self, column, nullable=False): - """Sets a column to be the the big integer increments representation for the table + """Sets a column to an auto-incrementing big integer Arguments: column {string} -- The column name. @@ -242,7 +240,6 @@ def big_increments(self, column, nullable=False): column, "big_increments", nullable=nullable ) - self.primary(column) return self def binary(self, column, nullable=False): From f578810a5fc8645c5f714fb7131e5513d640eef5 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:57:31 +0800 Subject: [PATCH 02/16] Updated data types removed unsigned from sqlite as its not supported --- .../schema/platforms/MySQLPlatform.py | 2 +- .../schema/platforms/PostgresPlatform.py | 6 +-- .../schema/platforms/SQLitePlatform.py | 49 ++++++++++--------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/masoniteorm/schema/platforms/MySQLPlatform.py b/src/masoniteorm/schema/platforms/MySQLPlatform.py index 23206274..8d83691b 100644 --- a/src/masoniteorm/schema/platforms/MySQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MySQLPlatform.py @@ -45,7 +45,7 @@ class MySQLPlatform(Platform): "date": "DATE", "year": "YEAR", "datetime": "DATETIME", - "tiny_increments": "TINYINT AUTO_INCREMENT", + "tiny_increments": "TINYINT UNSIGNED AUTO_INCREMENT", "unsigned": "INT UNSIGNED", } diff --git a/src/masoniteorm/schema/platforms/PostgresPlatform.py b/src/masoniteorm/schema/platforms/PostgresPlatform.py index 3b0184de..c25b59d4 100644 --- a/src/masoniteorm/schema/platforms/PostgresPlatform.py +++ b/src/masoniteorm/schema/platforms/PostgresPlatform.py @@ -22,7 +22,7 @@ class PostgresPlatform(Platform): "integer": "INTEGER", "big_integer": "BIGINT", "tiny_integer": "TINYINT", - "big_increments": "BIGSERIAL UNIQUE", + "big_increments": "BIGSERIAL", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", # Postgres database does not implement unsigned types @@ -32,7 +32,7 @@ class PostgresPlatform(Platform): "tiny_integer_unsigned": "TINYINT", "small_integer_unsigned": "SMALLINT", "medium_integer_unsigned": "MEDIUMINT", - "increments": "SERIAL UNIQUE", + "increments": "SERIAL", "uuid": "UUID", "binary": "BYTEA", "boolean": "BOOLEAN", @@ -55,7 +55,7 @@ class PostgresPlatform(Platform): "date": "DATE", "year": "YEAR", "datetime": "TIMESTAMPTZ", - "tiny_increments": "TINYINT AUTO_INCREMENT", + "tiny_increments": "SMALLSERIAL", "unsigned": "INT", } diff --git a/src/masoniteorm/schema/platforms/SQLitePlatform.py b/src/masoniteorm/schema/platforms/SQLitePlatform.py index f52ad14b..1d5edb85 100644 --- a/src/masoniteorm/schema/platforms/SQLitePlatform.py +++ b/src/masoniteorm/schema/platforms/SQLitePlatform.py @@ -1,3 +1,4 @@ +from ...exceptions import QueryException from ...schema import Schema from ..Table import Table from .Platform import Platform @@ -20,15 +21,15 @@ class SQLitePlatform(Platform): "integer": "INTEGER", "big_integer": "BIGINT", "tiny_integer": "TINYINT", - "big_increments": "BIGINT", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", - "integer_unsigned": "INT UNSIGNED", - "big_integer_unsigned": "BIGINT UNSIGNED", - "tiny_integer_unsigned": "TINYINT UNSIGNED", - "small_integer_unsigned": "SMALLINT UNSIGNED", - "medium_integer_unsigned": "MEDIUMINT UNSIGNED", - "increments": "INTEGER", + # Sqlite database does not implement unsigned types + # So the below types are the same as the normal ones + "integer_unsigned": "INT", + "big_integer_unsigned": "BIGINT", + "tiny_integer_unsigned": "TINYINT", + "small_integer_unsigned": "SMALLINT", + "medium_integer_unsigned": "MEDIUMINT", "uuid": "CHAR", "binary": "LONGBLOB", "boolean": "BOOLEAN", @@ -51,8 +52,13 @@ class SQLitePlatform(Platform): "date": "DATE", "year": "VARCHAR", "datetime": "DATETIME", - "tiny_increments": "TINYINT AUTO_INCREMENT", - "unsigned": "INT UNSIGNED", + "unsigned": "INT", + } + + unsupported_types = { + "tiny_increments": "tiny_increments() is not supported. For a primary key use '.tiny_integer('{}').primary()'", + "increments": "increments() is not supported. For a primary key use '.integer('{}').primary()'", + "big_increments": "big_increments() is not supported. For a primary key use '.big_integer('{}').primary()'", } premapped_defaults = { @@ -107,7 +113,15 @@ def compile_create_sql(self, table, if_not_exists=False): def columnize(self, columns): sql = [] + + # check for unsupported types for name, column in columns.items(): + if column.column_type in self.unsupported_types: + msg = self.unsupported_types[column.column_type].format( + column.name + ) + raise QueryException(msg) + if column.length: length = self.create_column_length(column.column_type).format( length=column.length @@ -148,12 +162,6 @@ def columnize(self, columns): data_type=self.type_map.get(column.column_type, ""), column_constraint=column_constraint, length=length, - signed=( - " " + self.signed.get(column._signed) - if column.column_type not in self.types_without_signs - and column._signed - else "" - ), constraint=constraint, nullable=self.premapped_nulls.get(column.is_null) or "", default=default, @@ -203,13 +211,6 @@ def compile_alter_sql(self, diff): column_constraint=column_constraint, nullable="NULL" if column.is_null else "NOT NULL", default=default, - signed=( - " " + self.signed.get(column._signed) - if column.column_type - not in self.types_without_signs - and column._signed - else "" - ), constraint=constraint, ) .strip() @@ -325,7 +326,7 @@ def get_column_string(self): return '"{column}"' def add_column_string(self): - return "ALTER TABLE {table} ADD COLUMN {name} {data_type}{column_constraint}{signed} {nullable}{default}{constraint}" + return "ALTER TABLE {table} ADD COLUMN {name} {data_type}{column_constraint} {nullable}{default}{constraint}" def create_column_length(self, column_type): if column_type in self.types_without_lengths: @@ -333,7 +334,7 @@ def create_column_length(self, column_type): return "({length})" def columnize_string(self): - return "{name} {data_type}{length}{column_constraint}{signed} {nullable}{default} {constraint}" + return "{name} {data_type}{length}{column_constraint} {nullable}{default} {constraint}" def get_unique_constraint_string(self): return "UNIQUE({columns})" From 3950cf59740a886b48bc83a00f246c9066e1de55 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:02:11 +0800 Subject: [PATCH 03/16] Tidy Platform Removed duplicate foreign key action added a raise for notImmplementedError for columnize as its customized per Platform anyway --- src/masoniteorm/schema/platforms/Platform.py | 40 +------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/src/masoniteorm/schema/platforms/Platform.py b/src/masoniteorm/schema/platforms/Platform.py index c39d65dd..677ad5f7 100644 --- a/src/masoniteorm/schema/platforms/Platform.py +++ b/src/masoniteorm/schema/platforms/Platform.py @@ -1,6 +1,5 @@ class Platform: foreign_key_actions = { - "cascade": "CASCADE", "set null": "SET NULL", "cascade": "CASCADE", "restrict": "RESTRICT", @@ -11,44 +10,7 @@ class Platform: signed = {"signed": "SIGNED", "unsigned": "UNSIGNED"} def columnize(self, columns): - sql = [] - for name, column in columns.items(): - if column.length: - length = self.create_column_length(column.column_type).format( - length=column.length - ) - else: - length = "" - - if column.default in (0,): - default = f" DEFAULT {column.default}" - elif column.default in self.premapped_defaults.keys(): - default = self.premapped_defaults.get(column.default) - elif column.default: - if ( - isinstance(column.default, (str,)) - and not column.default_is_raw - ): - default = f" DEFAULT '{column.default}'" - else: - default = f" DEFAULT {column.default}" - else: - default = "" - - sql.append( - self.columnize_string() - .format( - name=column.name, - data_type=self.type_map.get(column.column_type, ""), - length=length, - constraint="PRIMARY KEY" if column.primary else "", - nullable=self.premapped_nulls.get(column.is_null) or "", - default=default, - ) - .strip() - ) - - return sql + raise NotImplementedError def columnize_string(self): raise NotImplementedError From 82319f710e9e0336daeeb0d78960b075519a038c Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:10:21 +0800 Subject: [PATCH 04/16] updated schema builder tests --- orm.sqlite3 | Bin 188416 -> 204800 bytes .../mssql/schema/test_mssql_schema_builder.py | 35 ++++++++++------- .../mysql/schema/test_mysql_schema_builder.py | 31 ++++++++------- .../schema/test_postgres_schema_builder.py | 36 ++++++++++-------- 4 files changed, 61 insertions(+), 41 deletions(-) diff --git a/orm.sqlite3 b/orm.sqlite3 index cdda25e6cbe72200a2528df38cc8037284a18d9b..2cab693b2da7095616f9fed1cce182367f9a64ff 100644 GIT binary patch delta 3347 zcmZ{mc}x^n9LMK+@6DS%h6UvkWl=zGmIdTe6e!+})|e*NR#4d@xZL2a%hslcX#};& z8vm%(+NMpKSfrIio8Z-^@ei-s#y^ZU*5jWh_K#|fSnZqnX@FmJH}n1M_p@(icHYiR zruUSi_ms0gF*@d?BuRd;q>4q6B<9_d<5yx%4%8npor?KDSZSI$Vm=s*in?P`(elE^ z&XMGykz|>-t3PP%5!Nq%6Ecn(2aP@>WV9J|#u8(;k#8g$CV$57^PBu4ALd8-LEgth zyp7lKC44r|=gHjEpXvAYoBBn4SU;*C)OYLK^`O2|U#OSq8G4*f*#mZ){mRa;0rolT zV>?(2dz&p{-ls~)9jPPv2b8vIHb_{OON9rIu;BI ziUq+!!$KVuA((h&)PRt&kdO$Wz615`sBc4kD|Gn(tvTO<25d%s6Y3jL-++1#>fNY! z*?r9YrxOk6K)oIHHq={DZ$UkX`g*IsIRC8~Xhs8?P+y07BkJ#>9zeYT^|hj}g!?bt z`PZNUt5L54{_xnv%Q2b=i5#InNO`E*h!4LN8<8^aQC? z?1J^$De{Mn-K*CG1C5<+J?(WpU4hQgPyU)^wN=Y&z00er z7uR~HHtuW)7r{C)uUw}fa$QzxBfGich!iV|2R;RfvLSLwQT~&CLl;zKma=kb4UNmr zmRHyt>gotKbqDIY0v$bp*0ljt^T+)R^kqit>Xtx`STj@1^VYO9Ib0GM)|Bjt)}eIO zt!rv%2+(=fV}>MU&y5^7nlt;~^oCG%(V6LXmv@4n$a;%;{PTn}A8y54imce$Ncod=xt&UD9Lj$@8Z zj!K7SoHzQ7H;p8Ii+{~qd6E8DKc#=5FV>^kHTD^6U|IBUdYo>f)#3@`LOS`ByhXg) zUF}<~Q!7=Us^`>Q>QXgUxvm^m)+u@NKk^B=SNw;M)ROSReFIUYN_YWaK42bTt_3-~ z@4KinCHxw=8bCFm3NQyS8&C1*8DHfMmcFz+?+zcb5~y?k0gt1SA0B z0das>z(l|VKnx%n;ISY!c{)jK(gf!QxByOoL!iWKosZ%ri^Y0aP7q6hSbWbvCk%S( z|1kHq>qGh+7fEA5Z4OUi;p>@3^G-eB?cCjE-G&>}KI&XAAEQWB@#(7x1yTA}(_ zJ*|GEF2SdaJXdx~SET)758_o4HsI%QfDT{)3LpRtpaK+t43I3yAv<^2x!ulfc5bzE zi=CV8++^oQJ2%+bV`sOWU3PZb*kLtml}*GK&i Ds8qA+ delta 409 zcmZoTz|(MmdxDe@X9xoWgB}n=0gKl}9U~^rkc|mT__-MQe}jbe_Gc9PhecRSx|wWYy19Lj83VVK$U`w+Zp&b^E2=j@?PY5#N*E0$aS7e zh0~hDlD&j&7t0prjf~sbxPh8_8C9Fh8co>66%`rV%}WxKa#GWa@=FWiON&#B5G>{C zii}LIx}ko-p6-6GE((7BAqsw>K0Z1MN+5;tnJG#No_-;&?yf-!Fh$!N8JX%C8CAA3 zGBepSZRciVx*@4+q+noTWol++WMpJuWU6auq-%f>;stq9fPsPk5`zkmr2=%{3jXOk z1$o&5rnC(x!f>`dmFlQ#-j LY&W~Xbc!7SM7wAQ diff --git a/tests/mssql/schema/test_mssql_schema_builder.py b/tests/mssql/schema/test_mssql_schema_builder.py index 4205bc7e..364f2571 100644 --- a/tests/mssql/schema/test_mssql_schema_builder.py +++ b/tests/mssql/schema/test_mssql_schema_builder.py @@ -1,9 +1,9 @@ import unittest -from tests.integrations.config.database import DATABASES from src.masoniteorm.connections import MSSQLConnection from src.masoniteorm.schema import Schema from src.masoniteorm.schema.platforms import MSSQLPlatform +from tests.integrations.config.database import DATABASES class TestMSSQLSchemaBuilder(unittest.TestCase): @@ -26,7 +26,9 @@ def test_can_add_columns(self): self.assertEqual(len(blueprint.table.added_columns), 2) self.assertEqual( blueprint.to_sql(), - ["CREATE TABLE [users] ([name] VARCHAR(255) NOT NULL, [age] INT NOT NULL)"], + [ + "CREATE TABLE [users] ([name] VARCHAR(255) NOT NULL, [age] INT NOT NULL)" + ], ) def test_can_add_tiny_text(self): @@ -69,7 +71,10 @@ def test_can_have_float_type(self): self.assertEqual( blueprint.to_sql(), - ["""CREATE TABLE [users] (""" """[amount] FLOAT(19, 4) NOT NULL)"""], + [ + """CREATE TABLE [users] (""" + """[amount] FLOAT(19, 4) NOT NULL)""" + ], ) def test_can_have_unsigned_columns(self): @@ -134,14 +139,16 @@ def test_can_add_columns_with_add_foreign_constaint(self): def test_can_advanced_table_creation(self): with self.schema.create("users") as blueprint: - blueprint.increments("id") + blueprint.increments("id").primary() blueprint.string("name") blueprint.string("email").unique() blueprint.string("password") blueprint.integer("admin").default(0) blueprint.string("remember_token").nullable() blueprint.timestamp("verified_at").nullable() - blueprint.timestamp("registered_at").default_raw("CURRENT_TIMESTAMP") + blueprint.timestamp("registered_at").default_raw( + "CURRENT_TIMESTAMP" + ) blueprint.timestamps() self.assertEqual(len(blueprint.table.added_columns), 10) @@ -157,7 +164,7 @@ def test_can_advanced_table_creation(self): def test_can_advanced_table_creation2(self): with self.schema.create("users") as blueprint: - blueprint.increments("id") + blueprint.increments("id").primary() blueprint.enum("gender", ["male", "female"]) blueprint.string("name") blueprint.string("duration") @@ -169,9 +176,9 @@ def test_can_advanced_table_creation2(self): blueprint.string("thumbnail").nullable() blueprint.integer("premium") blueprint.integer("author_id").unsigned().nullable() - blueprint.foreign("author_id").references("id").on("users").on_delete( - "CASCADE" - ) + blueprint.foreign("author_id").references("id").on( + "users" + ).on_delete("CASCADE") blueprint.text("description") blueprint.timestamps() @@ -192,9 +199,9 @@ def test_can_advanced_table_creation2(self): def test_can_add_columns_with_foreign_key_constraint_name(self): with self.schema.create("users") as blueprint: blueprint.integer("profile_id") - blueprint.foreign("profile_id", name="profile_foreign").references("id").on( - "profiles" - ) + blueprint.foreign("profile_id", name="profile_foreign").references( + "id" + ).on("profiles") self.assertEqual(len(blueprint.table.added_columns), 1) self.assertEqual( @@ -315,7 +322,9 @@ def test_can_add_enum(self): def test_can_change_column_enum(self): with self.schema.table("users") as blueprint: - blueprint.enum("status", ["active", "inactive"]).default("active").change() + blueprint.enum("status", ["active", "inactive"]).default( + "active" + ).change() self.assertEqual(len(blueprint.table.changed_columns), 1) self.assertEqual( diff --git a/tests/mysql/schema/test_mysql_schema_builder.py b/tests/mysql/schema/test_mysql_schema_builder.py index b3aefc03..49269079 100644 --- a/tests/mysql/schema/test_mysql_schema_builder.py +++ b/tests/mysql/schema/test_mysql_schema_builder.py @@ -2,11 +2,9 @@ import unittest from src.masoniteorm import Model -from tests.integrations.config.database import DATABASES from src.masoniteorm.connections import MySQLConnection from src.masoniteorm.schema import Schema from src.masoniteorm.schema.platforms import MySQLPlatform - from tests.integrations.config.database import DATABASES @@ -56,7 +54,9 @@ def test_can_add_unsigned_decimal(self): self.assertEqual(len(blueprint.table.added_columns), 1) self.assertEqual( blueprint.to_sql(), - ["CREATE TABLE `users` (`amount` DECIMAL(19, 4) UNSIGNED NOT NULL)"], + [ + "CREATE TABLE `users` (`amount` DECIMAL(19, 4) UNSIGNED NOT NULL)" + ], ) def test_can_create_table_if_not_exists(self): @@ -119,7 +119,9 @@ def test_can_add_columns_with_foreign_key_constaint(self): blueprint.integer("profile_id") blueprint.foreign("profile_id").references("id").on("profiles") blueprint.foreign_id("post_id").references("id").on("posts") - blueprint.foreign_id_for(Discussion).references("id").on("discussions") + blueprint.foreign_id_for(Discussion).references("id").on( + "discussions" + ) self.assertEqual(len(blueprint.table.added_columns), 3) self.assertEqual( @@ -180,7 +182,7 @@ def test_can_advanced_table_creation(self): "`name` VARCHAR(255) NOT NULL, `active` TINYINT(1) NOT NULL, `email` VARCHAR(255) NOT NULL, `gender` ENUM('male', 'female') NOT NULL, " "`password` VARCHAR(255) NOT NULL, `money` DECIMAL(17, 6) NOT NULL, " "`admin` INT(11) NOT NULL DEFAULT 0, `option` VARCHAR(255) NOT NULL DEFAULT 'ADMIN', `remember_token` VARCHAR(255) NULL, `verified_at` TIMESTAMP NULL, " - "`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_id2_primary PRIMARY KEY (id2), CONSTRAINT users_email_unique UNIQUE (email))" + "`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_id2_primary PRIMARY KEY (id2), CONSTRAINT users_email_unique UNIQUE (email))" ], ) @@ -201,7 +203,7 @@ def test_can_add_primary_constraint_without_column_name(self): def test_can_advanced_table_creation2(self): with self.schema.create("users") as blueprint: - blueprint.big_increments("id") + blueprint.big_increments("id").primary() blueprint.string("name") blueprint.string("duration") blueprint.string("url") @@ -212,9 +214,9 @@ def test_can_advanced_table_creation2(self): blueprint.string("thumbnail").nullable() blueprint.integer("premium") blueprint.integer("author_id").unsigned().nullable() - blueprint.foreign("author_id").references("id").on("users").on_delete( - "CASCADE" - ) + blueprint.foreign("author_id").references("id").on( + "users" + ).on_delete("CASCADE") blueprint.text("description") blueprint.timestamps() @@ -233,9 +235,9 @@ def test_can_advanced_table_creation2(self): def test_can_add_columns_with_foreign_key_constraint_name(self): with self.schema.create("users") as blueprint: blueprint.integer("profile_id") - blueprint.foreign("profile_id", name="profile_foreign").references("id").on( - "profiles" - ) + blueprint.foreign("profile_id", name="profile_foreign").references( + "id" + ).on("profiles") self.assertEqual(len(blueprint.table.added_columns), 1) self.assertEqual( @@ -316,7 +318,10 @@ def test_can_have_default_blank_string(self): self.assertEqual( blueprint.to_sql(), - ["CREATE TABLE `users` (" "`profile_id` VARCHAR(255) NOT NULL DEFAULT '')"], + [ + "CREATE TABLE `users` (" + "`profile_id` VARCHAR(255) NOT NULL DEFAULT '')" + ], ) def test_can_have_float_type(self): diff --git a/tests/postgres/schema/test_postgres_schema_builder.py b/tests/postgres/schema/test_postgres_schema_builder.py index 9e04b3dd..918c1081 100644 --- a/tests/postgres/schema/test_postgres_schema_builder.py +++ b/tests/postgres/schema/test_postgres_schema_builder.py @@ -1,9 +1,9 @@ import unittest -from tests.integrations.config.database import DATABASES from src.masoniteorm.connections import PostgresConnection from src.masoniteorm.schema import Schema from src.masoniteorm.schema.platforms import PostgresPlatform +from tests.integrations.config.database import DATABASES class TestPostgresSchemaBuilder(unittest.TestCase): @@ -37,7 +37,8 @@ def test_can_add_tiny_text(self): self.assertEqual(len(blueprint.table.added_columns), 1) self.assertEqual( - blueprint.to_sql(), ['CREATE TABLE "users" ("description" TEXT NOT NULL)'] + blueprint.to_sql(), + ['CREATE TABLE "users" ("description" TEXT NOT NULL)'], ) def test_can_add_unsigned_decimal(self): @@ -138,7 +139,8 @@ def test_can_add_columns_with_long_text(self): self.assertEqual(len(blueprint.table.added_columns), 1) self.assertEqual( - blueprint.to_sql(), ['CREATE TABLE "users" ("description" TEXT NOT NULL)'] + blueprint.to_sql(), + ['CREATE TABLE "users" ("description" TEXT NOT NULL)'], ) def test_can_have_unsigned_columns(self): @@ -180,7 +182,7 @@ def test_can_add_columns_with_foreign_key_constaint(self): def test_can_advanced_table_creation(self): with self.schema.create("users") as blueprint: - blueprint.increments("id") + blueprint.increments("id").primary() blueprint.string("name") blueprint.string("email").unique() blueprint.string("password") @@ -193,7 +195,7 @@ def test_can_advanced_table_creation(self): self.assertEqual( blueprint.to_sql(), [ - 'CREATE TABLE "users" ("id" SERIAL UNIQUE NOT NULL, "name" VARCHAR(255) NOT NULL, ' + 'CREATE TABLE "users" ("id" SERIAL NOT NULL, "name" VARCHAR(255) NOT NULL, ' '"email" VARCHAR(255) NOT NULL, "password" VARCHAR(255) NOT NULL, "admin" INTEGER NOT NULL DEFAULT 0, ' '"remember_token" VARCHAR(255) NULL, "verified_at" TIMESTAMP NULL, ' '"created_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, ' @@ -203,7 +205,7 @@ def test_can_advanced_table_creation(self): def test_can_advanced_table_creation2(self): with self.schema.create("users") as blueprint: - blueprint.big_increments("id") + blueprint.big_increments("id").primary() blueprint.string("name") blueprint.enum("gender", ["male", "female"]) blueprint.string("duration") @@ -219,9 +221,9 @@ def test_can_advanced_table_creation2(self): blueprint.integer("premium") blueprint.double("amount").default(0.0) blueprint.integer("author_id").unsigned().nullable() - blueprint.foreign("author_id").references("id").on("authors").on_delete( - "CASCADE" - ) + blueprint.foreign("author_id").references("id").on( + "authors" + ).on_delete("CASCADE") blueprint.text("description") blueprint.timestamps() @@ -230,7 +232,7 @@ def test_can_advanced_table_creation2(self): blueprint.to_sql(), ( [ - """CREATE TABLE "users" ("id" BIGSERIAL UNIQUE NOT NULL, "name" VARCHAR(255) NOT NULL, "gender" VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, """ + """CREATE TABLE "users" ("id" BIGSERIAL NOT NULL, "name" VARCHAR(255) NOT NULL, "gender" VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, """ """"duration" VARCHAR(255) NOT NULL, "money" DECIMAL(17, 6) NOT NULL, "url" VARCHAR(255) NOT NULL, "option" VARCHAR(255) NOT NULL DEFAULT 'ADMIN', "payload" JSONB NOT NULL, "last_address" INET NULL, """ '"route_origin" CIDR NULL, "mac_address" MACADDR NULL, "published_at" TIMESTAMPTZ NOT NULL, "thumbnail" VARCHAR(255) NULL, "premium" INTEGER NOT NULL, "amount" DOUBLE PRECISION NOT NULL DEFAULT 0.0, ' '"author_id" INTEGER NULL, "description" TEXT NOT NULL, "created_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, ' @@ -261,9 +263,9 @@ def test_can_add_uuid_column(self): def test_can_add_columns_with_foreign_key_constraint_name(self): with self.schema.create("users") as blueprint: blueprint.integer("profile_id") - blueprint.foreign("profile_id", name="profile_foreign").references("id").on( - "profiles" - ) + blueprint.foreign("profile_id", name="profile_foreign").references( + "id" + ).on("profiles") self.assertEqual(len(blueprint.table.added_columns), 1) self.assertEqual( @@ -344,7 +346,10 @@ def test_can_have_float_type(self): self.assertEqual( blueprint.to_sql(), - ["""CREATE TABLE "users" (""" """\"amount" FLOAT(19, 4) NOT NULL)"""], + [ + """CREATE TABLE "users" (""" + """\"amount" FLOAT(19, 4) NOT NULL)""" + ], ) def test_can_enable_foreign_keys(self): @@ -377,6 +382,7 @@ def test_can_add_enum(self): self.assertEqual( blueprint.to_sql(), [ - 'CREATE TABLE "users" ("status" VARCHAR(255) CHECK(status IN (\'active\', \'inactive\')) NOT NULL ' 'DEFAULT \'active\')' + "CREATE TABLE \"users\" (\"status\" VARCHAR(255) CHECK(status IN ('active', 'inactive')) NOT NULL " + "DEFAULT 'active')" ], ) From b185276857eb0d62b31ef70c0d68d4881f5034d3 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:13:07 +0800 Subject: [PATCH 05/16] updated tests --- tests/sqlite/models/test_sqlite_model.py | 8 +++---- .../schema/test_sqlite_schema_builder.py | 22 +++++++++---------- .../test_sqlite_schema_builder_alter.py | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/sqlite/models/test_sqlite_model.py b/tests/sqlite/models/test_sqlite_model.py index 530c6641..b3bbfe44 100644 --- a/tests/sqlite/models/test_sqlite_model.py +++ b/tests/sqlite/models/test_sqlite_model.py @@ -221,19 +221,19 @@ def test_should_return_relation_applying_hidden_attributes(self): schema.drop_table_if_exists(table) with schema.create("users_hidden") as blueprint: - blueprint.increments("id") + blueprint.integer("id").primary() blueprint.string("name") blueprint.integer("token") blueprint.string("password") blueprint.timestamps() with schema.create("groups") as blueprint: - blueprint.increments("id") + blueprint.integer("id").primary() blueprint.string("name") blueprint.timestamps() with schema.create("group_user") as blueprint: - blueprint.increments("id") + blueprint.integer("id").primary() blueprint.unsigned_integer("group_id") blueprint.unsigned_integer("user_id") @@ -251,7 +251,7 @@ def test_should_return_relation_applying_hidden_attributes(self): user = UserHydrateHidden.first() group = Group.first() - group.attach_related("team", user) + group.attach("team", user) serialized = Group.first().serialize() diff --git a/tests/sqlite/schema/test_sqlite_schema_builder.py b/tests/sqlite/schema/test_sqlite_schema_builder.py index 461abd55..fd2a8096 100644 --- a/tests/sqlite/schema/test_sqlite_schema_builder.py +++ b/tests/sqlite/schema/test_sqlite_schema_builder.py @@ -136,7 +136,7 @@ def test_can_use_morphs_for_polymorphism_relationships(self): self.assertEqual(len(blueprint.table.added_columns), 2) sql = [ - 'CREATE TABLE "likes" ("record_id" INTEGER UNSIGNED NOT NULL, "record_type" VARCHAR(255) NOT NULL)', + 'CREATE TABLE "likes" ("record_id" INTEGER NOT NULL, "record_type" VARCHAR(255) NOT NULL)', 'CREATE INDEX likes_record_id_index ON "likes"(record_id)', 'CREATE INDEX likes_record_type_index ON "likes"(record_type)', ] @@ -144,7 +144,7 @@ def test_can_use_morphs_for_polymorphism_relationships(self): def test_can_advanced_table_creation(self): with self.schema.create("users") as blueprint: - blueprint.increments("id") + blueprint.integer("id") blueprint.string("name") blueprint.enum("gender", ["male", "female"]) blueprint.string("email").unique() @@ -163,7 +163,7 @@ def test_can_advanced_table_creation(self): """CREATE TABLE "users" ("id" INTEGER NOT NULL, "name" VARCHAR(255) NOT NULL, "gender" VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, "email" VARCHAR(255) NOT NULL, """ """"password" VARCHAR(255) NOT NULL, "option" VARCHAR(255) NOT NULL DEFAULT 'ADMIN', "admin" INTEGER NOT NULL DEFAULT 0, "remember_token" VARCHAR(255) NULL, """ '"verified_at" TIMESTAMP NULL, "created_at" DATETIME NULL DEFAULT CURRENT_TIMESTAMP, ' - '"updated_at" DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_id_primary PRIMARY KEY (id), ' + '"updated_at" DATETIME NULL DEFAULT CURRENT_TIMESTAMP, ' "UNIQUE(email), UNIQUE(email, name))" ], ) @@ -245,7 +245,8 @@ def test_can_have_column_primary_key(self): def test_can_advanced_table_creation2(self): with self.schema.create("users") as blueprint: - blueprint.big_increments("id") + blueprint.big_integer("id") + blueprint.primary("id") blueprint.string("name") blueprint.string("duration") blueprint.string("url") @@ -266,14 +267,13 @@ def test_can_advanced_table_creation2(self): blueprint.timestamps() self.assertEqual(len(blueprint.table.added_columns), 17) - self.assertEqual( blueprint.to_sql(), ( [ 'CREATE TABLE "users" ("id" BIGINT NOT NULL, "name" VARCHAR(255) NOT NULL, "duration" VARCHAR(255) NOT NULL, ' '"url" VARCHAR(255) NOT NULL, "payload" JSON NOT NULL, "birth" VARCHAR(4) NOT NULL, "last_address" VARCHAR(255) NULL, "route_origin" VARCHAR(255) NULL, "mac_address" VARCHAR(255) NULL, ' - '"published_at" DATETIME NOT NULL, "wakeup_at" TIME NOT NULL, "thumbnail" VARCHAR(255) NULL, "premium" INTEGER NOT NULL, "author_id" INTEGER UNSIGNED NULL, "description" TEXT NOT NULL, ' + '"published_at" DATETIME NOT NULL, "wakeup_at" TIME NOT NULL, "thumbnail" VARCHAR(255) NULL, "premium" INTEGER NOT NULL, "author_id" INTEGER NULL, "description" TEXT NOT NULL, ' '"created_at" DATETIME NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" DATETIME NULL DEFAULT CURRENT_TIMESTAMP, ' 'CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_author_id_foreign FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE SET NULL)' ] @@ -327,11 +327,11 @@ def test_can_have_unsigned_columns(self): blueprint.to_sql(), [ """CREATE TABLE "users" (""" - """"profile_id" INTEGER UNSIGNED NOT NULL, """ - """"big_profile_id" BIGINT UNSIGNED NOT NULL, """ - """"tiny_profile_id" TINYINT UNSIGNED NOT NULL, """ - """"small_profile_id" SMALLINT UNSIGNED NOT NULL, """ - """"medium_profile_id" MEDIUMINT UNSIGNED NOT NULL)""" + """"profile_id" INTEGER NOT NULL, """ + """"big_profile_id" BIGINT NOT NULL, """ + """"tiny_profile_id" TINYINT NOT NULL, """ + """"small_profile_id" SMALLINT NOT NULL, """ + """"medium_profile_id" MEDIUMINT NOT NULL)""" ], ) diff --git a/tests/sqlite/schema/test_sqlite_schema_builder_alter.py b/tests/sqlite/schema/test_sqlite_schema_builder_alter.py index 677b1445..ed5eb1db 100644 --- a/tests/sqlite/schema/test_sqlite_schema_builder_alter.py +++ b/tests/sqlite/schema/test_sqlite_schema_builder_alter.py @@ -177,10 +177,10 @@ def test_alter_add_column_and_foreign_key(self): blueprint.table.from_table = table sql = [ - 'ALTER TABLE "users" ADD COLUMN "playlist_id" INTEGER UNSIGNED NULL REFERENCES "playlists"("id")', + 'ALTER TABLE "users" ADD COLUMN "playlist_id" INTEGER NULL REFERENCES "playlists"("id")', "CREATE TEMPORARY TABLE __temp__users AS SELECT age, email FROM users", 'DROP TABLE "users"', - 'CREATE TABLE "users" ("age" VARCHAR NOT NULL, "email" VARCHAR NOT NULL, "playlist_id" INTEGER UNSIGNED NULL, ' + 'CREATE TABLE "users" ("age" VARCHAR NOT NULL, "email" VARCHAR NOT NULL, "playlist_id" INTEGER NULL, ' 'CONSTRAINT users_playlist_id_foreign FOREIGN KEY ("playlist_id") REFERENCES "playlists"("id") ON DELETE CASCADE ON UPDATE SET NULL)', 'INSERT INTO "users" ("age", "email") SELECT age, email FROM __temp__users', "DROP TABLE __temp__users", From c872b59cddbadc6fec47fe50d6827b6180a46ac9 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Fri, 5 Dec 2025 16:13:31 +0800 Subject: [PATCH 06/16] added test for unsupported types --- tests/sqlite/schema/test_sqlite_schema_builder.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/sqlite/schema/test_sqlite_schema_builder.py b/tests/sqlite/schema/test_sqlite_schema_builder.py index fd2a8096..1384ade0 100644 --- a/tests/sqlite/schema/test_sqlite_schema_builder.py +++ b/tests/sqlite/schema/test_sqlite_schema_builder.py @@ -1,5 +1,6 @@ import unittest +from src.masoniteorm.exceptions import QueryException from src.masoniteorm.schema import Schema from src.masoniteorm.schema.platforms import SQLitePlatform from tests.integrations.config.database import DATABASES @@ -243,6 +244,19 @@ def test_can_have_column_primary_key(self): ], ) + def test_cannot_have_unsupported_types(self): + with self.assertRaises(QueryException): + with self.schema.create("users100") as blueprint: + blueprint.increments("id").primary() + + with self.schema.create("users200") as blueprint: + blueprint.tiny_increments("id").primary() + blueprint.to_sql() + + with self.schema.create("users300") as blueprint: + blueprint.big_increments("id").primary() + blueprint.to_sql() + def test_can_advanced_table_creation2(self): with self.schema.create("users") as blueprint: blueprint.big_integer("id") From f18fe8f1d2703ff0d0e4cd03ac71f9241a87bab3 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Sat, 6 Dec 2025 08:11:02 +0800 Subject: [PATCH 07/16] updated changelogUpdated CHANGELOG --- CHANGELOG.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2527dec8..77958fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [3.0.0] - 2025-03-30 +## [3.0.0] - 2025-12-05 ### Changed @@ -9,6 +9,7 @@ #### Breaking Changes +- Using `*increments()` for primary key definition now requires adding `.primay()` to the column definition. - Changed raw expressions placeholder from requiringing explicit quoring per grammar (like this '?') to automaic (like this ?) - Changed `update` and `delete` methods to return the affected rows instead of the model - Seeding depencies are now in a separate`[seeder]` extension @@ -16,8 +17,12 @@ ### Fixed - - Model `update` and `delete` not casting passed values +- QueryBuilder does not require `database.py` when passing connection detain in directly +- Import DB (ConnectionResolver) from config even if inline connection details are provided +- `*increments()` can be used fir non primary key columns if supported by the platform +- `*increments()` can be used fir non primary key columns if supported by the platform + - Model `update` and `delete` not casting passed values ## [2.24.0] - 2025-01-23 From 459fcba92f794cb864649a78d82bdf3648b13752 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Sat, 6 Dec 2025 08:34:59 +0800 Subject: [PATCH 08/16] fixed migrations table definition --- orm.sqlite3 | Bin 204800 -> 204800 bytes src/masoniteorm/migrations/Migration.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/orm.sqlite3 b/orm.sqlite3 index 2cab693b2da7095616f9fed1cce182367f9a64ff..1ce4c6615a1414c40f212d52ee3bbeb9fafacbdf 100644 GIT binary patch delta 280 zcmZoTz|(MmXM(igUj_ySBOq1*VkQO#cB6?p#*BX(6SgKWF6n39&f>S7eF9@PBMVDB zi{EBJg&Ryte2os=48lO=V33uc%GYR*DzLp^3S)l`qs=x(rss@|*4tk&F)=YRT5W&L z%p}RgZNmoE*r?rTyPcnn>58O^nSz0Vm9dGHp^=e+k*Thsk*)zkh!?2ZiIHbIy8=@q v3!@t&&tyS`24?d{pXr85OqPt^U}}4lB2(f$S%fYu25n(}%#UBiq67f|{scVw delta 219 zcmZoTz|(MmXM(igZUzPhBOq1*VkQO#c7=&L#*Dig6SgKWF6n39%2KeMeF9@P<7PpH ze@xp8rZD#BFq&**WO~lXXuSOe6B837qtW))%uJF@+$L;5BN!MOwHr;h^RqEskyJ5N zFtD&PFt;)^FfuSQ)ipHIH9!dQ0@XS&HcV$%U}~H!sPJQZgCbM%Jz0bTEPA#uKjz1; IVo`zs0A8~+WdHyG diff --git a/src/masoniteorm/migrations/Migration.py b/src/masoniteorm/migrations/Migration.py index 51291e5d..db41d58c 100644 --- a/src/masoniteorm/migrations/Migration.py +++ b/src/masoniteorm/migrations/Migration.py @@ -46,7 +46,7 @@ def __init__( def create_table_if_not_exists(self): if not self.schema.has_table("migrations"): with self.schema.create("migrations") as table: - table.increments("migration_id") + table.increments("migration_id").primary() table.string("migration") table.integer("batch") From 0fe876afc2f257dc9177a90e70cd7b63f488ab68 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Sat, 6 Dec 2025 08:44:13 +0800 Subject: [PATCH 09/16] Fixed migrations --- .../2018_01_09_043202_create_users_table.py | 26 ++++++++---------- .../2020_04_17_000000_create_friends_table.py | 13 +++++---- .../2020_04_17_00000_create_articles_table.py | 13 +++++---- ...20_152904_create_table_schema_migration.py | 4 +-- orm.sqlite3 | Bin 204800 -> 204800 bytes 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/databases/migrations/2018_01_09_043202_create_users_table.py b/databases/migrations/2018_01_09_043202_create_users_table.py index 218419b9..d2c09516 100644 --- a/databases/migrations/2018_01_09_043202_create_users_table.py +++ b/databases/migrations/2018_01_09_043202_create_users_table.py @@ -6,23 +6,21 @@ class CreateUsersTable(Migration): def up(self): """Run the migrations.""" - with self.schema.create('users') as table: - table.increments('id') - table.string('name') - table.string('email').unique() - table.string('password') - table.string('second_password').nullable() - table.string('remember_token').nullable() - table.timestamp('verified_at').nullable() + with self.schema.create("users") as table: + table.increments("id").primary() + table.string("name") + table.string("email").unique() + table.string("password") + table.string("second_password").nullable() + table.string("remember_token").nullable() + table.timestamp("verified_at").nullable() table.timestamps() if not self.schema._dry: - User.on(self.connection).set_schema(self.schema_name).create({ - 'name': 'Joe', - 'email': 'joe@email.com', - 'password': 'secret' - }) + User.on(self.connection).set_schema(self.schema_name).create( + {"name": "Joe", "email": "joe@email.com", "password": "secret"} + ) def down(self): """Revert the migrations.""" - self.schema.drop('users') + self.schema.drop("users") diff --git a/databases/migrations/2020_04_17_000000_create_friends_table.py b/databases/migrations/2020_04_17_000000_create_friends_table.py index 425f5113..2df9ab46 100644 --- a/databases/migrations/2020_04_17_000000_create_friends_table.py +++ b/databases/migrations/2020_04_17_000000_create_friends_table.py @@ -1,19 +1,20 @@ from src.masoniteorm.migrations.Migration import Migration + class CreateFriendsTable(Migration): - def up(self): + def up(self): """ Run the migrations. """ - with self.schema.create('friends') as table: - table.increments('id') - table.string('name') - table.integer('age') + with self.schema.create("friends") as table: + table.increments("id").primary() + table.string("name") + table.integer("age") def down(self): """ Revert the migrations. """ - self.schema.drop('friends') \ No newline at end of file + self.schema.drop("friends") diff --git a/databases/migrations/2020_04_17_00000_create_articles_table.py b/databases/migrations/2020_04_17_00000_create_articles_table.py index 8fe7f70c..754608ea 100644 --- a/databases/migrations/2020_04_17_00000_create_articles_table.py +++ b/databases/migrations/2020_04_17_00000_create_articles_table.py @@ -1,18 +1,19 @@ from src.masoniteorm.migrations.Migration import Migration + class CreateArticlesTable(Migration): - def up(self): + def up(self): """ Run the migrations. """ - with self.schema.create('fans') as table: - table.increments('id') - table.string('name') - table.integer('age') + with self.schema.create("fans") as table: + table.increments("id").primary() + table.string("name") + table.integer("age") def down(self): """ Revert the migrations. """ - self.schema.drop('fans') \ No newline at end of file + self.schema.drop("fans") diff --git a/databases/migrations/2020_10_20_152904_create_table_schema_migration.py b/databases/migrations/2020_10_20_152904_create_table_schema_migration.py index 63268b9e..126b8789 100644 --- a/databases/migrations/2020_10_20_152904_create_table_schema_migration.py +++ b/databases/migrations/2020_10_20_152904_create_table_schema_migration.py @@ -10,8 +10,8 @@ def up(self): Run the migrations. """ with self.schema.create("table_schema") as table: - table.increments('id') - table.string('name') + table.increments("id").primary() + table.string("name") table.timestamps() def down(self): diff --git a/orm.sqlite3 b/orm.sqlite3 index 1ce4c6615a1414c40f212d52ee3bbeb9fafacbdf..6cb4cad2c9b30873c5ebf1d04f62fe64772be655 100644 GIT binary patch delta 244 zcmZoTz|(MmXM&WFh#Uh0gAov`05KB-1H1J^9U~?YxyFR835-knnRl?*ZfBpsn9s<> zV!K&T;V6?JU!x;8gD_Av7-Z$AZugtQxG{&(VH+dUb4Et{?Jt;^m>3!Dw!da(l4Rm` zU<0db)NXX#&dk{*~ZB9oRQIb`wJ!}CPqf9?XQ`cB$>Ev*nnm*Ff?j6+HU7(W4b9R zZ){>^Xk=tyWU6auq-$WNU|?Vc7UBgeb7JI~&aS}JHd#oap4q(7XS$&hljU{~MWzM! RByj25!u*0Cr{tmp0RVzzGhhG! From 09f71e8f9283ed33031759fc095520babd72daa8 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Sun, 7 Dec 2025 09:34:28 +0800 Subject: [PATCH 10/16] fixed single columns not being marked as primary key --- src/masoniteorm/schema/Blueprint.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/masoniteorm/schema/Blueprint.py b/src/masoniteorm/schema/Blueprint.py index f6c219d5..297976c3 100644 --- a/src/masoniteorm/schema/Blueprint.py +++ b/src/masoniteorm/schema/Blueprint.py @@ -902,6 +902,9 @@ def primary(self, column=None, name=None): column = self._last_column.name if not isinstance(column, list): + self.table.set_primary_key(column) + if self.table.added_columns.get(column): + self.table.added_columns[column].set_as_primary() column = [column] self.table.add_constraint( From 6f20237522152cde168826a2b2632b81231439c7 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Sun, 7 Dec 2025 09:36:36 +0800 Subject: [PATCH 11/16] removed redundant PRIMARY KEY identifier As we are using CONSTRAINT for primary keys we dont need this identifier as well --- src/masoniteorm/schema/platforms/MSSQLPlatform.py | 3 --- src/masoniteorm/schema/platforms/MySQLPlatform.py | 3 --- src/masoniteorm/schema/platforms/PostgresPlatform.py | 3 --- src/masoniteorm/schema/platforms/SQLitePlatform.py | 3 --- 4 files changed, 12 deletions(-) diff --git a/src/masoniteorm/schema/platforms/MSSQLPlatform.py b/src/masoniteorm/schema/platforms/MSSQLPlatform.py index 0ee57b2a..6dca54b8 100644 --- a/src/masoniteorm/schema/platforms/MSSQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MSSQLPlatform.py @@ -261,9 +261,6 @@ def columnize(self, columns): constraint = "" column_constraint = "" - if column.primary: - constraint = " PRIMARY KEY" - if column.column_type == "enum": values = ", ".join(f"'{x}'" for x in column.values) column_constraint = f" CHECK([{column.name}] IN ({values}))" diff --git a/src/masoniteorm/schema/platforms/MySQLPlatform.py b/src/masoniteorm/schema/platforms/MySQLPlatform.py index 8d83691b..63b002cd 100644 --- a/src/masoniteorm/schema/platforms/MySQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MySQLPlatform.py @@ -88,9 +88,6 @@ def columnize(self, columns): constraint = "" column_constraint = "" - if column.primary: - constraint = "PRIMARY KEY" - if column.column_type == "enum": values = ", ".join(f"'{x}'" for x in column.values) column_constraint = f"({values})" diff --git a/src/masoniteorm/schema/platforms/PostgresPlatform.py b/src/masoniteorm/schema/platforms/PostgresPlatform.py index c25b59d4..07d77c2d 100644 --- a/src/masoniteorm/schema/platforms/PostgresPlatform.py +++ b/src/masoniteorm/schema/platforms/PostgresPlatform.py @@ -161,9 +161,6 @@ def columnize(self, columns): constraint = "" column_constraint = "" - if column.primary: - constraint = "PRIMARY KEY" - if column.column_type == "enum": values = ", ".join(f"'{x}'" for x in column.values) column_constraint = f" CHECK({column.name} IN ({values}))" diff --git a/src/masoniteorm/schema/platforms/SQLitePlatform.py b/src/masoniteorm/schema/platforms/SQLitePlatform.py index 1d5edb85..702798e3 100644 --- a/src/masoniteorm/schema/platforms/SQLitePlatform.py +++ b/src/masoniteorm/schema/platforms/SQLitePlatform.py @@ -148,9 +148,6 @@ def columnize(self, columns): constraint = "" column_constraint = "" - if column.primary: - constraint = "PRIMARY KEY" - if column.column_type == "enum": values = ", ".join(f"'{x}'" for x in column.values) column_constraint = f" CHECK({column.name} IN ({values}))" From 249e8dc8cb3aafa1a663e001dfce9a088a0e3ade Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Sun, 7 Dec 2025 09:38:22 +0800 Subject: [PATCH 12/16] Fixed tests --- orm.sqlite3 | Bin 204800 -> 204800 bytes .../schema/platforms/SQLitePlatform.py | 9 ++++++--- .../schema/test_sqlite_schema_builder.py | 11 ++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/orm.sqlite3 b/orm.sqlite3 index 6cb4cad2c9b30873c5ebf1d04f62fe64772be655..461d8c476ea4548ae87c253bf512e4781f7a3ee0 100644 GIT binary patch delta 1021 zcma))OH30%7=U;F*>0^{x_w02qDU#N9)!4E0vkv)%0qlXc|}A}R?|j#Bv2|h6IeOO z#ROAv@Xp1Xq~hL86CW}0;E@D1@nndSKukCY8k}}akckI3`RAMc_W$>vN&cyvb1LVY zE%6o`f*@!#A~Zk{?8^@-H7GU~jRnPpm33+bP1#m9mG!LG{YjDNdxhCHy;){$mLZ>E z?Q_EiC8CGaSbcSMy;`fOT1{05y%f#dijuEK|~3|m=Gs2@$b%x+om<Ig#Lq!uW8hO#MS6C+=qE~&QEiCwnZ37(#{KBf; zKx?8%uXitd+V;e5z5j`HjCSVia9Cc2FT#%Glw?WHctZ1YZ=uGPY?)3BKSB^fs#T8Q zH7Xgh`-4F=-Fy4`jgjQd@zIH~G+V<2VOT|jHs)ta5PHl8$xk!V98Cdu<{=h*(A&pdkAKn^M&?w(akmz3qu`hEx>Y>!!Or?82u8U zq0$Kd*$1;8)Bk^CWEC}tHv}tTYjl9f zHflFIPUmN1Qkm}eiBWF)VQwag>92k>3QzClWa8Q0!N%0cxt+6t@fQE|$NbES%+3s# zrn4(Bbxhpk%xvE1JKa!;$#OfNBGX?!QBZV90 Date: Mon, 8 Dec 2025 15:58:27 +0800 Subject: [PATCH 13/16] fixed using increments types as a primary key *increments() data types mpw use column attributes instead of constraints to define the column as a primary key. This standardises using *increments accross all platforms --- src/masoniteorm/schema/Blueprint.py | 19 ++++++++++-- .../schema/platforms/MSSQLPlatform.py | 9 ++++-- .../schema/platforms/MySQLPlatform.py | 9 ++++-- .../schema/platforms/PostgresPlatform.py | 9 ++++-- .../schema/platforms/SQLitePlatform.py | 30 +++++++++++-------- .../mssql/schema/test_mssql_schema_builder.py | 8 ++--- .../mysql/schema/test_mysql_schema_builder.py | 9 +++--- .../schema/test_postgres_schema_builder.py | 8 ++--- 8 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/masoniteorm/schema/Blueprint.py b/src/masoniteorm/schema/Blueprint.py index 297976c3..f1171028 100644 --- a/src/masoniteorm/schema/Blueprint.py +++ b/src/masoniteorm/schema/Blueprint.py @@ -903,8 +903,23 @@ def primary(self, column=None, name=None): if not isinstance(column, list): self.table.set_primary_key(column) - if self.table.added_columns.get(column): - self.table.added_columns[column].set_as_primary() + check_column = self.table.added_columns.get(column) + if check_column: + check_column.set_as_primary() + if check_column.column_type in [ + "tiny_increments", + "increments", + "big_increments", + ]: + # use column attributes for primary key auto increment columns + check_column.column_type = ( + f"{check_column.column_type}_primary" + ) + self.table.added_columns[column] = check_column + return self + + self.table.added_columns[column] = check_column + column = [column] self.table.add_constraint( diff --git a/src/masoniteorm/schema/platforms/MSSQLPlatform.py b/src/masoniteorm/schema/platforms/MSSQLPlatform.py index 6dca54b8..1f6db4bd 100644 --- a/src/masoniteorm/schema/platforms/MSSQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MSSQLPlatform.py @@ -14,7 +14,6 @@ class MSSQLPlatform(Platform): type_map = { "string": "VARCHAR", "char": "CHAR", - "big_increments": "BIGINT IDENTITY", "integer": "INT", "big_integer": "BIGINT", "tiny_integer": "TINYINT", @@ -25,7 +24,6 @@ class MSSQLPlatform(Platform): "tiny_integer_unsigned": "TINYINT", "small_integer_unsigned": "SMALLINT", "medium_integer_unsigned": "MEDIUMINT", - "increments": "INT IDENTITY", "uuid": "CHAR", "binary": "LONGBLOB", "boolean": "BOOLEAN", @@ -48,9 +46,14 @@ class MSSQLPlatform(Platform): "date": "DATE", "year": "YEAR", "datetime": "DATETIME", - "tiny_increments": "TINYINT IDENTITY", "unsigned": "INT", "unsigned_integer": "INT", + "tiny_increments": "TINYINT IDENTITY", + "increments": "INT IDENTITY", + "big_increments": "BIGINT IDENTITY", + "tiny_increments_primary": "TINYINT PRIMARY KEY IDENTITY", + "increments_primary": "INT PRIMARY KEY IDENTITY", + "big_increments_primary": "BIGINT PRIMARY KEY IDENTITY", } premapped_nulls = {True: "NULL", False: "NOT NULL"} diff --git a/src/masoniteorm/schema/platforms/MySQLPlatform.py b/src/masoniteorm/schema/platforms/MySQLPlatform.py index 63b002cd..935b0787 100644 --- a/src/masoniteorm/schema/platforms/MySQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MySQLPlatform.py @@ -21,8 +21,6 @@ class MySQLPlatform(Platform): "tiny_integer_unsigned": "TINYINT UNSIGNED", "small_integer_unsigned": "SMALLINT UNSIGNED", "medium_integer_unsigned": "MEDIUMINT UNSIGNED", - "big_increments": "BIGINT UNSIGNED AUTO_INCREMENT", - "increments": "INT UNSIGNED AUTO_INCREMENT", "uuid": "CHAR", "binary": "LONGBLOB", "boolean": "BOOLEAN", @@ -45,8 +43,13 @@ class MySQLPlatform(Platform): "date": "DATE", "year": "YEAR", "datetime": "DATETIME", - "tiny_increments": "TINYINT UNSIGNED AUTO_INCREMENT", "unsigned": "INT UNSIGNED", + "tiny_increments": "TINYINT UNSIGNED AUTO_INCREMENT", + "increments": "INT UNSIGNED AUTO_INCREMENT", + "big_increments": "BIGINT UNSIGNED AUTO_INCREMENT", + "tiny_increments_primary": "TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT", + "increments_primary": "INT UNSIGNED PRIMARY KEY AUTO_INCREMENT", + "big_increments_primary": "BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT", } premapped_nulls = {True: "NULL", False: "NOT NULL"} diff --git a/src/masoniteorm/schema/platforms/PostgresPlatform.py b/src/masoniteorm/schema/platforms/PostgresPlatform.py index 07d77c2d..bf8facb9 100644 --- a/src/masoniteorm/schema/platforms/PostgresPlatform.py +++ b/src/masoniteorm/schema/platforms/PostgresPlatform.py @@ -22,7 +22,6 @@ class PostgresPlatform(Platform): "integer": "INTEGER", "big_integer": "BIGINT", "tiny_integer": "TINYINT", - "big_increments": "BIGSERIAL", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", # Postgres database does not implement unsigned types @@ -32,7 +31,6 @@ class PostgresPlatform(Platform): "tiny_integer_unsigned": "TINYINT", "small_integer_unsigned": "SMALLINT", "medium_integer_unsigned": "MEDIUMINT", - "increments": "SERIAL", "uuid": "UUID", "binary": "BYTEA", "boolean": "BOOLEAN", @@ -55,8 +53,13 @@ class PostgresPlatform(Platform): "date": "DATE", "year": "YEAR", "datetime": "TIMESTAMPTZ", - "tiny_increments": "SMALLSERIAL", "unsigned": "INT", + "tiny_increments": "SMALLSERIAL", + "increments": "SERIAL", + "big_increments": "BIGSERIAL", + "tiny_increments_primary": "SMALLSERIAL PRIMARY KEY", + "increments_primary": "SERIAL PRIMARY KEY", + "big_increments_primary": "BIGSERIAL PRIMARY KEY", } table_info_map = { diff --git a/src/masoniteorm/schema/platforms/SQLitePlatform.py b/src/masoniteorm/schema/platforms/SQLitePlatform.py index 3604f380..d0df9ac7 100644 --- a/src/masoniteorm/schema/platforms/SQLitePlatform.py +++ b/src/masoniteorm/schema/platforms/SQLitePlatform.py @@ -53,12 +53,18 @@ class SQLitePlatform(Platform): "year": "VARCHAR", "datetime": "DATETIME", "unsigned": "INT", + "tiny_increments": "TINYINT", + "increments": "INTEGER", + "big_increments": "BIGINT", + "tiny_increments_primary": "TINYINT PRIMARY KEY AUTOINCREMENT", + "increments_primary": "INTEGER PRIMARY KEY AUTOINCREMENT", + "big_increments_primary": "BIGINT PRIMARY KEY AUTOINCREMENT", } primary_key_type_check = { - "tiny_increments": "tiny_increments() is not supported. For a primary key use '.tiny_integer('{}').primary()'", - "increments": "increments() is not supported. For a primary key use '.integer('{}').primary()'", - "big_increments": "big_increments() is not supported. For a primary key use '.big_integer('{}').primary()'", + "tiny_increments": "tiny_increments() not supported on non-primary key columns. For a primary key use '.tiny_increments('{}').primary()'", + "increments": "increments() not supported on non-primary key columns. For a primary key use '.increments('{}').primary()'", + "big_increments": "big_increments() not supported on non-primary key columns. For a primary key use '.big_increments('{}').primary()'", } premapped_defaults = { @@ -116,14 +122,15 @@ def columnize(self, columns): # check for unsupported types for name, column in columns.items(): - if ( - column.column_type in self.primary_key_type_check - and not column.primary - ): - msg = self.primary_key_type_check[column.column_type].format( - column.name - ) - raise QueryException(msg) + constraint = "" + if column.column_type in self.primary_key_type_check: + if not column.primary: + msg = self.primary_key_type_check[ + column.column_type + ].format(column.name) + raise QueryException(msg) + + constraint = "PRIMARY KEY AUTOINCREMENT" if column.length: length = self.create_column_length(column.column_type).format( @@ -149,7 +156,6 @@ def columnize(self, columns): else: default = "" - constraint = "" column_constraint = "" if column.column_type == "enum": values = ", ".join(f"'{x}'" for x in column.values) diff --git a/tests/mssql/schema/test_mssql_schema_builder.py b/tests/mssql/schema/test_mssql_schema_builder.py index 364f2571..7ab18e66 100644 --- a/tests/mssql/schema/test_mssql_schema_builder.py +++ b/tests/mssql/schema/test_mssql_schema_builder.py @@ -155,10 +155,10 @@ def test_can_advanced_table_creation(self): self.assertEqual( blueprint.to_sql(), [ - "CREATE TABLE [users] ([id] INT IDENTITY NOT NULL, [name] VARCHAR(255) NOT NULL, [email] VARCHAR(255) NOT NULL, " + "CREATE TABLE [users] ([id] INT PRIMARY KEY IDENTITY NOT NULL, [name] VARCHAR(255) NOT NULL, [email] VARCHAR(255) NOT NULL, " "[password] VARCHAR(255) NOT NULL, [admin] INT NOT NULL DEFAULT 0, [remember_token] VARCHAR(255) NULL, " "[verified_at] DATETIME NULL, [registered_at] DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, [created_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, " - "[updated_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_email_unique UNIQUE (email))" + "[updated_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_email_unique UNIQUE (email))" ], ) @@ -187,11 +187,11 @@ def test_can_advanced_table_creation2(self): blueprint.to_sql(), ( [ - "CREATE TABLE [users] ([id] INT IDENTITY NOT NULL, [gender] VARCHAR(255) NOT NULL CHECK([gender] IN ('male', 'female')), [name] VARCHAR(255) NOT NULL, [duration] VARCHAR(255) NOT NULL, " + "CREATE TABLE [users] ([id] INT PRIMARY KEY IDENTITY NOT NULL, [gender] VARCHAR(255) NOT NULL CHECK([gender] IN ('male', 'female')), [name] VARCHAR(255) NOT NULL, [duration] VARCHAR(255) NOT NULL, " "[url] VARCHAR(255) NOT NULL, [last_address] VARCHAR(255) NULL, [route_origin] VARCHAR(255) NULL, [mac_address] VARCHAR(255) NULL, [published_at] DATETIME NOT NULL, [thumbnail] VARCHAR(255) NULL, [premium] INT NOT NULL, " "[author_id] INT NULL, [description] TEXT NOT NULL, [created_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, " "[updated_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, " - "CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_author_id_foreign FOREIGN KEY ([author_id]) REFERENCES [users]([id]) ON DELETE CASCADE)" + "CONSTRAINT users_author_id_foreign FOREIGN KEY ([author_id]) REFERENCES [users]([id]) ON DELETE CASCADE)" ] ), ) diff --git a/tests/mysql/schema/test_mysql_schema_builder.py b/tests/mysql/schema/test_mysql_schema_builder.py index 49269079..69fabbe5 100644 --- a/tests/mysql/schema/test_mysql_schema_builder.py +++ b/tests/mysql/schema/test_mysql_schema_builder.py @@ -178,11 +178,12 @@ def test_can_advanced_table_creation(self): blueprint.to_sql(), [ "CREATE TABLE `users` (`id` INT UNSIGNED AUTO_INCREMENT NOT NULL, " - "`id2` BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, " + "`id2` BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL, " "`name` VARCHAR(255) NOT NULL, `active` TINYINT(1) NOT NULL, `email` VARCHAR(255) NOT NULL, `gender` ENUM('male', 'female') NOT NULL, " "`password` VARCHAR(255) NOT NULL, `money` DECIMAL(17, 6) NOT NULL, " "`admin` INT(11) NOT NULL DEFAULT 0, `option` VARCHAR(255) NOT NULL DEFAULT 'ADMIN', `remember_token` VARCHAR(255) NULL, `verified_at` TIMESTAMP NULL, " - "`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_id2_primary PRIMARY KEY (id2), CONSTRAINT users_email_unique UNIQUE (email))" + "`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, " + "CONSTRAINT users_email_unique UNIQUE (email))" ], ) @@ -224,11 +225,11 @@ def test_can_advanced_table_creation2(self): self.assertEqual( blueprint.to_sql(), [ - "CREATE TABLE `users` (`id` BIGINT UNSIGNED AUTO_INCREMENT NOT NULL, `name` VARCHAR(255) NOT NULL, " + "CREATE TABLE `users` (`id` BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT NOT NULL, `name` VARCHAR(255) NOT NULL, " "`duration` VARCHAR(255) NOT NULL, `url` VARCHAR(255) NOT NULL, `last_address` VARCHAR(255) NULL, `route_origin` VARCHAR(255) NULL, `mac_address` VARCHAR(255) NULL, " "`published_at` DATETIME NOT NULL, `thumbnail` VARCHAR(255) NULL, " "`premium` INT(11) NOT NULL, `author_id` INT(11) UNSIGNED NULL, `description` TEXT NOT NULL, `created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, " - "`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_author_id_foreign FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE CASCADE)" + "`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_author_id_foreign FOREIGN KEY (`author_id`) REFERENCES `users`(`id`) ON DELETE CASCADE)" ], ) diff --git a/tests/postgres/schema/test_postgres_schema_builder.py b/tests/postgres/schema/test_postgres_schema_builder.py index 918c1081..4eb13eca 100644 --- a/tests/postgres/schema/test_postgres_schema_builder.py +++ b/tests/postgres/schema/test_postgres_schema_builder.py @@ -195,11 +195,11 @@ def test_can_advanced_table_creation(self): self.assertEqual( blueprint.to_sql(), [ - 'CREATE TABLE "users" ("id" SERIAL NOT NULL, "name" VARCHAR(255) NOT NULL, ' + 'CREATE TABLE "users" ("id" SERIAL PRIMARY KEY NOT NULL, "name" VARCHAR(255) NOT NULL, ' '"email" VARCHAR(255) NOT NULL, "password" VARCHAR(255) NOT NULL, "admin" INTEGER NOT NULL DEFAULT 0, ' '"remember_token" VARCHAR(255) NULL, "verified_at" TIMESTAMP NULL, ' '"created_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, ' - "CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_email_unique UNIQUE (email))" + "CONSTRAINT users_email_unique UNIQUE (email))" ], ) @@ -232,12 +232,12 @@ def test_can_advanced_table_creation2(self): blueprint.to_sql(), ( [ - """CREATE TABLE "users" ("id" BIGSERIAL NOT NULL, "name" VARCHAR(255) NOT NULL, "gender" VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, """ + """CREATE TABLE "users" ("id" BIGSERIAL PRIMARY KEY NOT NULL, "name" VARCHAR(255) NOT NULL, "gender" VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, """ """"duration" VARCHAR(255) NOT NULL, "money" DECIMAL(17, 6) NOT NULL, "url" VARCHAR(255) NOT NULL, "option" VARCHAR(255) NOT NULL DEFAULT 'ADMIN', "payload" JSONB NOT NULL, "last_address" INET NULL, """ '"route_origin" CIDR NULL, "mac_address" MACADDR NULL, "published_at" TIMESTAMPTZ NOT NULL, "thumbnail" VARCHAR(255) NULL, "premium" INTEGER NOT NULL, "amount" DOUBLE PRECISION NOT NULL DEFAULT 0.0, ' '"author_id" INTEGER NULL, "description" TEXT NOT NULL, "created_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, ' '"updated_at" TIMESTAMPTZ NULL DEFAULT CURRENT_TIMESTAMP, ' - 'CONSTRAINT users_id_primary PRIMARY KEY (id), CONSTRAINT users_author_id_foreign FOREIGN KEY ("author_id") REFERENCES "authors"("id") ON DELETE CASCADE)' + 'CONSTRAINT users_author_id_foreign FOREIGN KEY ("author_id") REFERENCES "authors"("id") ON DELETE CASCADE)' ] ), ) From f101f0876a9ba3d3a4cdeb9585c819819881aa63 Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:05:24 +0800 Subject: [PATCH 14/16] added migrations table tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as migrations table uses increments(“migration_id”).primary() this is an ideal place to test the creation works correctly --- orm.sqlite3 | Bin 204800 -> 212992 bytes tests/migrations/test_migrations_table.py | 29 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/migrations/test_migrations_table.py diff --git a/orm.sqlite3 b/orm.sqlite3 index 461d8c476ea4548ae87c253bf512e4781f7a3ee0..8f57e34f8367f4d0647dac1a28f74aa441a47035 100644 GIT binary patch delta 2300 zcmeIzZ)h839Ki8=ewRN>lY5@D8I*1ryQX=etQ~2Zx@Ce>BpZX-&aPdZf7YaJnzU=1 zHc7X3|I)i6qHnB=?m%Js!aswFSPPAe3H8m~8!ZZhDyW-+P!*~#_NIH|U4FwfKl;{p z1}@*@!*j_U_uM_R%bwX;WqwDU|EeTO5p#R^aSgoD90vc@h4}lzYZGf0N5lhhU#yF@ z#qHiZ!eL5SubW%nU0UDG{Ks4&6Ra(;SR4OSEX}fC#h(3YsQo}BdZ0ZN4u#uWTEi`& z3faxUOl+9nQk&Q)@p(4S3a|#N@D(h<2k<7$K^78l3=YCx*aaT;fc?(CXSb~*B#CQ7 zZpnxHk~ES@axF<=kir0k{%R<2Em198i&N;MaEii96keq80)^+xa0;)dd^IQOkmo4$ zQaC}Ory4%mxXcvm&IPrhrS}+%x0w4rX;~7BLgJIkx1L`-huvDuN=?x9__nAs@3`Se z!!_F{a<4rpEf;Im%fY!pJ?N}&Y-F$a@`?V@WGb7Pn&_L#C9{=1gUPVH^caH$ChyU@ z4dH<6HvPCBDE%SBapuQg=4 zoku#J?utDV>*!WHI?b);=+S1iGSIl^hMkc_ejpuCk92g$4#&Fw9rvhK(3_m~4GnDW zWaU(I<BP(Cdl| z-uVs&Xi+3dk3PR<DyBtBoDeY)5lx~_F#Z?+nSaB- z;2-mM_-lNIr+F_w#M^n0`#30nD|eL@^QnAUDRA9c{X*lqgMyucje<-8C@>0A848=` zbAb%eE>XBh;R1#86wXnYse*#J#!Xj=31=ysp)f@uPa#JkOJUN2hu4pb?F1c?p)gKi tjKU~|(-cNF!$E72AKok$q$#ATK{4+d6SpLB%bY|vg}hJqnGfQ=e*l+;$oBvM delta 639 zcmZo@;B7d-GeJs7EP;W6!3c;|fS8Gaf&KbK9U~^OgpCPH`1zRm-vdP%jQD@^f8~F_ zUFZPQUH<0x^4s6bGs*;P=1%y_zn!Cj@ixDU@bBNwH-T{i<7PpH7{=|tjF{MXw=G~~OwebYz#zo%pMiffKLcMO??s+R zJnr0$T<5t|IITG>*-O}VvDz`eV0y;zpN)r&n~i(2pu!C97QSXac5y{T#`g57r Date: Mon, 8 Dec 2025 16:10:06 +0800 Subject: [PATCH 15/16] Updated Schema to use connection_details when provided --- src/masoniteorm/schema/Schema.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/masoniteorm/schema/Schema.py b/src/masoniteorm/schema/Schema.py index eaedabf8..3b2499e5 100644 --- a/src/masoniteorm/schema/Schema.py +++ b/src/masoniteorm/schema/Schema.py @@ -1,4 +1,5 @@ from ..config import load_config +from ..connections import ConnectionResolver from ..exceptions import ConnectionNotRegistered from .Blueprint import Blueprint from .Table import Table @@ -87,8 +88,14 @@ def on(self, connection_key): Returns: cls """ - resolver = load_config(config_path=self.config_path).DB - self.connection_details = resolver.get_connection_details() + if not self.connection_details: + resolver = ConnectionResolver( + connection_details=self.connection_details + ) + else: + 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: From bc19c25b00ba427391241c691fca90b1f4e8a6af Mon Sep 17 00:00:00 2001 From: Kieren Eaton <499977+circulon@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:13:41 +0800 Subject: [PATCH 16/16] removed test that was causing a false fail --- orm.sqlite3 | Bin 212992 -> 212992 bytes .../test_sqlite_schema_builder_alter.py | 16 +++------------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/orm.sqlite3 b/orm.sqlite3 index 8f57e34f8367f4d0647dac1a28f74aa441a47035..e23f98787952be0dba386886b6f0e5e1edc3bedb 100644 GIT binary patch delta 275 zcmZo@;B9E&oggi^kAZ=~1c;%4GkcFfuSQ z)ipHIHLy@HfCz2>-_LlYfKg-W5hevj$*oVBN|_kdrbja~sW2){7Gx9NKAD+Gj*&x^ zU0hL-vB_|{&R0gs>6ciTrZK8-&tzpY2(CjK4<{$u<-KvfO=%;rrZ(+!1~Eg6L; IZxk>G0Lo%RhX4Qo delta 245 zcmZo@;B9E&ogghZkAZ=~1c;%4GkKzpG2^_(gslmTE9-_LlYfKg@Y5hevjrL9kyN|_jyrbja~sW3`T7Gx9NKAD+Gj*&x= zU0hL-vB_|{&R0gs>6ciTrZFmS&tzpjt+f&Um#WDh^Hd6V$ujRNKXUy?t2 diff --git a/tests/sqlite/schema/test_sqlite_schema_builder_alter.py b/tests/sqlite/schema/test_sqlite_schema_builder_alter.py index ed5eb1db..84472804 100644 --- a/tests/sqlite/schema/test_sqlite_schema_builder_alter.py +++ b/tests/sqlite/schema/test_sqlite_schema_builder_alter.py @@ -9,8 +9,9 @@ class TestSQLiteSchemaBuilderAlter(unittest.TestCase): maxDiff = None - def setUp(self): - self.schema = Schema( + @classmethod + def setUpClass(cls): + cls.schema = Schema( connection="dev", connection_details=DATABASES, platform=SQLitePlatform, @@ -142,17 +143,6 @@ def test_timestamp_alter_add_nullable_column(self): self.assertEqual(blueprint.to_sql(), sql) - def test_alter_drop_on_table_schema_table(self): - schema = Schema(connection="dev", connection_details=DATABASES).on( - "dev" - ) - - with schema.table("table_schema") as blueprint: - blueprint.drop_column("name") - - with schema.table("table_schema") as blueprint: - blueprint.string("name").nullable() - def test_alter_add_primary(self): with self.schema.table("users") as blueprint: blueprint.primary("playlist_id")