From 8f89f3cb258218cc284f0c0ce8415c0634d4ebe2 Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Wed, 3 Feb 2021 18:05:04 -0500 Subject: [PATCH 1/4] added missing query builder method --- src/masoniteorm/models/Model.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/masoniteorm/models/Model.py b/src/masoniteorm/models/Model.py index 0ebb8ce4..caeb0725 100644 --- a/src/masoniteorm/models/Model.py +++ b/src/masoniteorm/models/Model.py @@ -124,6 +124,7 @@ class Model(TimeStampsMixin, ObservesEvents, metaclass=ModelMeta): "where_like", "where_not_like", "where_null", + "where_raw", "where", "with_", ] From 4fdb18183e5d1ecbefed36091099ce98448465cb Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Thu, 4 Feb 2021 23:44:54 -0500 Subject: [PATCH 2/4] added fix for tests --- src/masoniteorm/schema/Blueprint.py | 6 +- src/masoniteorm/schema/Table.py | 3 + .../schema/platforms/MSSQLPlatform.py | 6 +- .../schema/platforms/MySQLPlatform.py | 24 ++++-- .../schema/platforms/PostgresPlatform.py | 2 +- .../schema/platforms/SQLitePlatform.py | 2 +- .../mssql/schema/test_mssql_schema_builder.py | 4 +- .../mysql/schema/test_mysql_schema_builder.py | 76 ++++++++++--------- .../schema/test_mysql_schema_builder_alter.py | 24 +++--- .../schema/test_postgres_schema_builder.py | 7 +- .../schema/test_sqlite_schema_builder.py | 6 +- 11 files changed, 89 insertions(+), 71 deletions(-) diff --git a/src/masoniteorm/schema/Blueprint.py b/src/masoniteorm/schema/Blueprint.py index 8e04bdbc..a37e6ee7 100644 --- a/src/masoniteorm/schema/Blueprint.py +++ b/src/masoniteorm/schema/Blueprint.py @@ -153,7 +153,7 @@ def increments(self, column, nullable=False): self """ self._last_column = self.table.add_column( - column, "increments", nullable=nullable + column, "increments", nullable=nullable, primary=True ) return self @@ -170,7 +170,7 @@ def tiny_increments(self, column, nullable=False): self """ self._last_column = self.table.add_column( - column, "tiny_increments", nullable=nullable + column, "tiny_increments", nullable=nullable, primary=True ) return self @@ -204,7 +204,7 @@ def big_increments(self, column, nullable=False): self """ self._last_column = self.table.add_column( - column, "big_increments", nullable=nullable + column, "big_increments", nullable=nullable, primary=True ) return self diff --git a/src/masoniteorm/schema/Table.py b/src/masoniteorm/schema/Table.py index 63d3df15..9f4d14fb 100644 --- a/src/masoniteorm/schema/Table.py +++ b/src/masoniteorm/schema/Table.py @@ -24,6 +24,7 @@ def add_column( values=None, nullable=False, default=None, + primary=False, ): column = Column( name, @@ -33,6 +34,8 @@ def add_column( values=values or [], default=default, ) + if primary: + column.set_as_primary() self.added_columns.update({name: column}) return column diff --git a/src/masoniteorm/schema/platforms/MSSQLPlatform.py b/src/masoniteorm/schema/platforms/MSSQLPlatform.py index 93f2f4f1..169e6680 100644 --- a/src/masoniteorm/schema/platforms/MSSQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MSSQLPlatform.py @@ -18,10 +18,10 @@ class MSSQLPlatform(Platform): "integer": "INT", "big_integer": "BIGINT", "tiny_integer": "TINYINT", - "big_increments": "BIGINT IDENTITY PRIMARY KEY", + "big_increments": "BIGINT IDENTITY", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", - "increments": "INT IDENTITY PRIMARY KEY", + "increments": "INT IDENTITY", "uuid": "CHAR", "binary": "LONGBLOB", "boolean": "BOOLEAN", @@ -192,7 +192,7 @@ def columnize(self, columns): constraint = "" column_constraint = "" if column.primary: - constraint = "PRIMARY KEY" + constraint = " PRIMARY KEY" if column.column_type == "enum": values = ", ".join(f"'{x}'" for x in column.values) diff --git a/src/masoniteorm/schema/platforms/MySQLPlatform.py b/src/masoniteorm/schema/platforms/MySQLPlatform.py index 6556da7a..999cd6a5 100644 --- a/src/masoniteorm/schema/platforms/MySQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MySQLPlatform.py @@ -14,7 +14,7 @@ class MySQLPlatform(Platform): "big_increments": "BIGINT AUTO_INCREMENT", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", - "increments": "INT UNSIGNED AUTO_INCREMENT PRIMARY KEY", + "increments": "INT UNSIGNED AUTO_INCREMENT", "uuid": "CHAR", "binary": "LONGBLOB", "boolean": "BOOLEAN", @@ -80,7 +80,7 @@ def columnize(self, columns): sql.append( self.columnize_string() .format( - name=column.name, + name=self.get_column_string().format(column=column.name), data_type=self.type_map.get(column.column_type, ""), column_constraint=column_constraint, length=length, @@ -98,7 +98,7 @@ def compile_create_sql(self, table): sql.append( self.create_format().format( - table=table.name, + table=self.get_table_string().format(table=table.name), columns=", ".join(self.columnize(table.get_added_columns())).strip(), constraints=", " + ", ".join(self.constraintize(table.get_added_constraints(), table)) @@ -132,7 +132,7 @@ def compile_alter_sql(self, table): add_columns.append( self.add_column_string() .format( - name=column.name, + name=self.get_column_string().format(column=column.name), data_type=self.type_map.get(column.column_type, ""), length=length, constraint="PRIMARY KEY" if column.primary else "", @@ -160,7 +160,12 @@ def compile_alter_sql(self, table): length = "" renamed_sql.append( - self.rename_column_string().format(to=column.name, old=name).strip() + self.rename_column_string() + .format( + to=self.get_column_string().format(column=column.name), + old=self.get_column_string().format(column=name), + ) + .strip() ) sql.append( @@ -184,7 +189,11 @@ def compile_alter_sql(self, table): dropped_sql = [] for name in table.get_dropped_columns(): - dropped_sql.append(self.drop_column_string().format(name=name).strip()) + dropped_sql.append( + self.drop_column_string() + .format(name=self.get_column_string().format(column=name)) + .strip() + ) sql.append( self.alter_format().format( @@ -264,6 +273,9 @@ def constraintize(self, constraints, table): def get_table_string(self): return "`{table}`" + def get_column_string(self): + return "`{column}`" + def create_format(self): return "CREATE TABLE {table} ({columns}{constraints}{foreign_keys})" diff --git a/src/masoniteorm/schema/platforms/PostgresPlatform.py b/src/masoniteorm/schema/platforms/PostgresPlatform.py index 9d3626ce..dd4f82f2 100644 --- a/src/masoniteorm/schema/platforms/PostgresPlatform.py +++ b/src/masoniteorm/schema/platforms/PostgresPlatform.py @@ -17,7 +17,7 @@ class PostgresPlatform(Platform): "integer": "INTEGER", "big_integer": "BIGINT", "tiny_integer": "TINYINT", - "big_increments": "SERIAL UNIQUE", + "big_increments": "BIGSERIAL UNIQUE", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", "increments": "SERIAL UNIQUE", diff --git a/src/masoniteorm/schema/platforms/SQLitePlatform.py b/src/masoniteorm/schema/platforms/SQLitePlatform.py index eeaa5971..9654a33a 100644 --- a/src/masoniteorm/schema/platforms/SQLitePlatform.py +++ b/src/masoniteorm/schema/platforms/SQLitePlatform.py @@ -21,7 +21,7 @@ class SQLitePlatform(Platform): "big_increments": "BIGINT", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", - "increments": "INTEGER PRIMARY KEY", + "increments": "INTEGER", "uuid": "CHAR", "binary": "LONGBLOB", "boolean": "BOOLEAN", diff --git a/tests/mssql/schema/test_mssql_schema_builder.py b/tests/mssql/schema/test_mssql_schema_builder.py index 54d5695d..f095c106 100644 --- a/tests/mssql/schema/test_mssql_schema_builder.py +++ b/tests/mssql/schema/test_mssql_schema_builder.py @@ -74,7 +74,7 @@ def test_can_advanced_table_creation(self): self.assertEqual( blueprint.to_sql(), ( - "CREATE TABLE [users] ([id] INT IDENTITY PRIMARY KEY NOT NULL, [name] VARCHAR(255) NOT NULL, [email] VARCHAR(255) NOT NULL, " + "CREATE TABLE [users] ([id] INT IDENTITY NOT NULL PRIMARY KEY, [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 DEFAULT CURRENT_TIMESTAMP, [created_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, " "[updated_at] DATETIME NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_email_unique UNIQUE (email))" @@ -102,7 +102,7 @@ def test_can_advanced_table_creation2(self): self.assertEqual( blueprint.to_sql(), ( - "CREATE TABLE [users] ([id] INT IDENTITY PRIMARY KEY 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 IDENTITY NOT NULL PRIMARY KEY, [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, [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, " diff --git a/tests/mysql/schema/test_mysql_schema_builder.py b/tests/mysql/schema/test_mysql_schema_builder.py index 6df5a5ca..477140e0 100644 --- a/tests/mysql/schema/test_mysql_schema_builder.py +++ b/tests/mysql/schema/test_mysql_schema_builder.py @@ -27,7 +27,7 @@ def test_can_add_columns1(self): self.assertEqual(len(blueprint.table.added_columns), 2) self.assertEqual( blueprint.to_sql(), - "CREATE TABLE users (name VARCHAR(255) NOT NULL, age INT(11) NOT NULL)", + "CREATE TABLE `users` (`name` VARCHAR(255) NOT NULL, `age` INT(11) NOT NULL)", ) def test_can_add_columns_with_constaint(self): @@ -39,7 +39,7 @@ def test_can_add_columns_with_constaint(self): self.assertEqual(len(blueprint.table.added_columns), 2) self.assertEqual( blueprint.to_sql(), - "CREATE TABLE users (name VARCHAR(255) NOT NULL, age INT(11) NOT NULL, CONSTRAINT users_name_unique UNIQUE (name))", + "CREATE TABLE `users` (`name` VARCHAR(255) NOT NULL, `age` INT(11) NOT NULL, CONSTRAINT users_name_unique UNIQUE (name))", ) def test_can_add_columns_with_foreign_key_constaint(self): @@ -52,9 +52,9 @@ def test_can_add_columns_with_foreign_key_constaint(self): self.assertEqual(len(blueprint.table.added_columns), 3) self.assertEqual( blueprint.to_sql(), - "CREATE TABLE users (name VARCHAR(255) NOT NULL, " - "age INT(11) NOT NULL, " - "profile_id INT(11) NOT NULL, " + "CREATE TABLE `users` (`name` VARCHAR(255) NOT NULL, " + "`age` INT(11) NOT NULL, " + "`profile_id` INT(11) NOT NULL, " "CONSTRAINT users_name_unique UNIQUE (name), " "CONSTRAINT users_profile_id_foreign FOREIGN KEY (profile_id) REFERENCES profiles(id))", ) @@ -75,14 +75,15 @@ def test_can_advanced_table_creation(self): blueprint.timestamps() self.assertEqual(len(blueprint.table.added_columns), 13) + print(blueprint.to_sql()) self.assertEqual( blueprint.to_sql(), ( - "CREATE TABLE users (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY 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 DEFAULT CURRENT_TIMESTAMP, " - "created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_email_unique UNIQUE (email))" + "CREATE TABLE `users` (`id` INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, " + "`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 DEFAULT CURRENT_TIMESTAMP, " + "`created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_email_unique UNIQUE (email))" ), ) @@ -92,38 +93,39 @@ def test_can_add_primary_constraint_without_column_name(self): blueprint.string("name") blueprint.string("email") self.assertEqual(len(blueprint.table.added_columns), 3) + print(blueprint.to_sql()) self.assertTrue( blueprint.to_sql().startswith( - "CREATE TABLE users (user_id INT(11) NOT NULL PRIMARY KEY" + "CREATE TABLE `users` (`user_id` INT(11) NOT NULL PRIMARY KEY" ) ) - # def test_can_advanced_table_creation2(self): - # with self.schema.create("users") as blueprint: - # blueprint.increments("id") - # blueprint.string("name") - # blueprint.string("duration") - # blueprint.string("url") - # blueprint.datetime("published_at") - # 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.text("description") - # blueprint.timestamps() - - # self.assertEqual(len(blueprint.table.added_columns), 11) - # self.assertEqual( - # blueprint.to_sql(), - # ( - # "CREATE TABLE users (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), " - # "duration VARCHAR(255), url VARCHAR(255), published_at DATETIME, thumbnail VARCHAR(255), " - # "premium INT(11), author_id INT UNSIGNED, description TEXT, created_at TIMESTAMP, " - # "updated_at TIMESTAMP, CONSTRAINT users_author_id_foreign FOREIGN KEY (author_id) REFERENCES users(id))" - # ), - # ) + def test_can_advanced_table_creation2(self): + with self.schema.create("users") as blueprint: + blueprint.big_increments("id") + blueprint.string("name") + blueprint.string("duration") + blueprint.string("url") + blueprint.datetime("published_at") + 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.text("description") + blueprint.timestamps() + + self.assertEqual(len(blueprint.table.added_columns), 11) + self.assertEqual( + blueprint.to_sql(), + ( + "CREATE TABLE `users` (`id` INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL, " + "`duration` VARCHAR(255) NOT NULL, `url` VARCHAR(255) NOT NULL, `published_at` DATETIME NOT NULL, `thumbnail` VARCHAR(255) NULL, " + "`premium` INT(11) NOT NULL, `author_id` INT UNSIGNED NULL, `description` TEXT NOT NULL, `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " + "`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_author_id_foreign FOREIGN KEY (author_id) REFERENCES users(id))" + ), + ) def test_has_table(self): schema_sql = self.schema.has_table("users") diff --git a/tests/mysql/schema/test_mysql_schema_builder_alter.py b/tests/mysql/schema/test_mysql_schema_builder_alter.py index b8b606c9..b30f92f6 100644 --- a/tests/mysql/schema/test_mysql_schema_builder_alter.py +++ b/tests/mysql/schema/test_mysql_schema_builder_alter.py @@ -29,7 +29,7 @@ def test_can_add_columns(self): self.assertEqual(len(blueprint.table.added_columns), 2) sql = [ - "ALTER TABLE `users` ADD name VARCHAR(255) NOT NULL, ADD age INT(11) NOT NULL" + "ALTER TABLE `users` ADD `name` VARCHAR(255) NOT NULL, ADD `age` INT(11) NOT NULL" ] self.assertEqual(blueprint.to_sql(), sql) @@ -42,7 +42,7 @@ def test_alter_rename(self): table.add_column("post", "integer") blueprint.table.from_table = table - sql = ["ALTER TABLE `users` RENAME COLUMN post TO comment"] + sql = ["ALTER TABLE `users` RENAME COLUMN `post` TO `comment`"] self.assertEqual(blueprint.to_sql(), sql) @@ -56,8 +56,8 @@ def test_alter_add_and_rename(self): blueprint.table.from_table = table sql = [ - "ALTER TABLE `users` ADD name VARCHAR(255) NOT NULL", - "ALTER TABLE `users` RENAME COLUMN post TO comment", + "ALTER TABLE `users` ADD `name` VARCHAR(255) NOT NULL", + "ALTER TABLE `users` RENAME COLUMN `post` TO `comment`", ] self.assertEqual(blueprint.to_sql(), sql) @@ -66,7 +66,7 @@ def test_alter_drop1(self): with self.schema.table("users") as blueprint: blueprint.drop_column("post") - sql = ["ALTER TABLE `users` DROP COLUMN post"] + sql = ["ALTER TABLE `users` DROP COLUMN `post`"] self.assertEqual(blueprint.to_sql(), sql) @@ -76,7 +76,7 @@ def test_alter_add_column_and_foreign_key(self): blueprint.foreign("playlist_id").references("id").on("playlists") sql = [ - "ALTER TABLE `users` ADD playlist_id INT UNSIGNED NULL", + "ALTER TABLE `users` ADD `playlist_id` INT UNSIGNED NULL", "ALTER TABLE `users` ADD CONSTRAINT users_playlist_id_foreign FOREIGN KEY (playlist_id) REFERENCES playlists(id)", ] @@ -151,8 +151,8 @@ def test_change(self): blueprint.table.from_table = table sql = [ - "ALTER TABLE `users` ADD name VARCHAR(255) NOT NULL", - "ALTER TABLE `users` MODIFY age INT(11) NOT NULL", + "ALTER TABLE `users` ADD `name` VARCHAR(255) NOT NULL", + "ALTER TABLE `users` MODIFY `age` INT(11) NOT NULL", ] self.assertEqual(blueprint.to_sql(), sql) @@ -168,7 +168,7 @@ def test_timestamp_alter_add_nullable_column(self): blueprint.table.from_table = table - sql = ["ALTER TABLE `users` ADD due_date TIMESTAMP NULL"] + sql = ["ALTER TABLE `users` ADD `due_date` TIMESTAMP NULL"] self.assertEqual(blueprint.to_sql(), sql) @@ -187,9 +187,9 @@ def test_drop_add_and_change(self): blueprint.table.from_table = table sql = [ - "ALTER TABLE `users` ADD name VARCHAR(255) NOT NULL", - "ALTER TABLE `users` MODIFY age INT(11) NOT NULL DEFAULT 0", - "ALTER TABLE `users` DROP COLUMN email", + "ALTER TABLE `users` ADD `name` VARCHAR(255) NOT NULL", + "ALTER TABLE `users` MODIFY `age` INT(11) NOT NULL DEFAULT 0", + "ALTER TABLE `users` DROP COLUMN `email`", ] self.assertEqual(blueprint.to_sql(), sql) diff --git a/tests/postgres/schema/test_postgres_schema_builder.py b/tests/postgres/schema/test_postgres_schema_builder.py index 3167c87f..3997621d 100644 --- a/tests/postgres/schema/test_postgres_schema_builder.py +++ b/tests/postgres/schema/test_postgres_schema_builder.py @@ -99,7 +99,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 UNIQUE NOT NULL PRIMARY KEY, 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 DEFAULT CURRENT_TIMESTAMP, " "created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " @@ -109,7 +109,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.big_increments("id") blueprint.string("name") blueprint.enum("gender", ["male", "female"]) blueprint.string("duration") @@ -129,10 +129,11 @@ def test_can_advanced_table_creation2(self): blueprint.timestamps() self.assertEqual(len(blueprint.table.added_columns), 16) + print(blueprint.to_sql()) self.assertEqual( blueprint.to_sql(), ( - """CREATE TABLE "users" (id SERIAL UNIQUE NOT NULL, name VARCHAR(255) NOT NULL, gender VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, """ + """CREATE TABLE "users" (id BIGSERIAL UNIQUE NOT NULL PRIMARY KEY, 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, published_at TIMESTAMP NOT NULL, " "thumbnail VARCHAR(255) NULL, premium INTEGER NOT NULL, amount DOUBLE PRECISION NOT NULL DEFAULT 0.0, author_id INT NULL, " "description TEXT NOT NULL, created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " diff --git a/tests/sqlite/schema/test_sqlite_schema_builder.py b/tests/sqlite/schema/test_sqlite_schema_builder.py index eebfbfee..30d3440b 100644 --- a/tests/sqlite/schema/test_sqlite_schema_builder.py +++ b/tests/sqlite/schema/test_sqlite_schema_builder.py @@ -87,7 +87,7 @@ def test_can_advanced_table_creation(self): self.assertEqual( blueprint.to_sql(), ( - """CREATE TABLE "users" (id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(255) NOT NULL, gender VARCHAR(255) CHECK(gender IN ('male', 'female')) NOT NULL, email VARCHAR(255) NOT NULL, """ + """CREATE TABLE "users" (id INTEGER NOT NULL PRIMARY KEY, 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 DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " "updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE(email))" @@ -96,7 +96,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.big_increments("id") blueprint.string("name") blueprint.string("duration") blueprint.string("url") @@ -119,7 +119,7 @@ def test_can_advanced_table_creation2(self): self.assertEqual( blueprint.to_sql(), ( - 'CREATE TABLE "users" (id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(255) NOT NULL, duration VARCHAR(255) NOT NULL, ' + 'CREATE TABLE "users" (id BIGINT NOT NULL PRIMARY KEY, name VARCHAR(255) NOT NULL, duration VARCHAR(255) NOT NULL, ' "url VARCHAR(255) NOT NULL, payload JSON NOT NULL, birth VARCHAR(4) NOT NULL, published_at DATETIME NOT NULL, wakeup_at TIME NOT NULL, thumbnail VARCHAR(255) NULL, premium INTEGER NOT NULL, " "author_id UNSIGNED INT NULL, description TEXT NOT NULL, created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " "updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " From 9e81485c51824acd819a57367cc20928e9c0a147 Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Thu, 4 Feb 2021 23:48:52 -0500 Subject: [PATCH 3/4] added sqlite connection fix --- src/masoniteorm/connections/SQLiteConnection.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/masoniteorm/connections/SQLiteConnection.py b/src/masoniteorm/connections/SQLiteConnection.py index bdf2ab3c..12f05499 100644 --- a/src/masoniteorm/connections/SQLiteConnection.py +++ b/src/masoniteorm/connections/SQLiteConnection.py @@ -1,4 +1,3 @@ -import sqlite3 from ..query.grammars import SQLiteGrammar from .BaseConnection import BaseConnection from ..schema.platforms import SQLitePlatform @@ -46,6 +45,12 @@ def __init__( def make_connection(self): """This sets the connection on the connection class""" + try: + import sqlite3 + except ModuleNotFoundError: + raise DriverNotFound( + "You must have the 'sqlite3' package installed to make a connection to MySQL. Please install it using 'pip install pymysql'" + ) if self.has_global_connection(): return self.get_global_connection() From c71058d488718dec3dd5a9b0d9adc8e33d791aed Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Thu, 4 Feb 2021 23:56:38 -0500 Subject: [PATCH 4/4] fixed test --- src/masoniteorm/schema/platforms/MySQLPlatform.py | 2 +- tests/mysql/schema/test_mysql_schema_builder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/masoniteorm/schema/platforms/MySQLPlatform.py b/src/masoniteorm/schema/platforms/MySQLPlatform.py index 999cd6a5..868b948a 100644 --- a/src/masoniteorm/schema/platforms/MySQLPlatform.py +++ b/src/masoniteorm/schema/platforms/MySQLPlatform.py @@ -11,7 +11,7 @@ class MySQLPlatform(Platform): "integer": "INT", "big_integer": "BIGINT", "tiny_integer": "TINYINT", - "big_increments": "BIGINT AUTO_INCREMENT", + "big_increments": "BIGINT UNSIGNED AUTO_INCREMENT", "small_integer": "SMALLINT", "medium_integer": "MEDIUMINT", "increments": "INT UNSIGNED AUTO_INCREMENT", diff --git a/tests/mysql/schema/test_mysql_schema_builder.py b/tests/mysql/schema/test_mysql_schema_builder.py index 477140e0..340bb5f7 100644 --- a/tests/mysql/schema/test_mysql_schema_builder.py +++ b/tests/mysql/schema/test_mysql_schema_builder.py @@ -120,7 +120,7 @@ def test_can_advanced_table_creation2(self): self.assertEqual( blueprint.to_sql(), ( - "CREATE TABLE `users` (`id` INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL, " + "CREATE TABLE `users` (`id` BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` VARCHAR(255) NOT NULL, " "`duration` VARCHAR(255) NOT NULL, `url` VARCHAR(255) NOT NULL, `published_at` DATETIME NOT NULL, `thumbnail` VARCHAR(255) NULL, " "`premium` INT(11) NOT NULL, `author_id` INT UNSIGNED NULL, `description` TEXT NOT NULL, `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, " "`updated_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT users_author_id_foreign FOREIGN KEY (author_id) REFERENCES users(id))"