From 1d2e235fc87649cee18431f81928b37569700473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 27 Oct 2022 14:10:52 -0300 Subject: [PATCH 1/5] refactor(provider): remove artisan project validation --- app/Console/Exceptions/Handler.js | 24 +++++ app/Console/Kernel.js | 21 ++++ app/Resources/UserResource.js | 15 +++ config/app.js | 5 + config/database.js | 95 +++++++++++++++++++ config/logging.js | 48 ++++++++++ ...08_000000_create_uuid_function_postgres.js | 30 ++++++ ...2_10_08_000001_create_users_mysql_table.js | 38 ++++++++ ...0_08_000002_create_products_mysql_table.js | 40 ++++++++ ...0_08_000003_create_users_postgres_table.js | 38 ++++++++ ...8_000004_create_products_postgres_table.js | 40 ++++++++ ...022_10_08_000005_create_countries_table.js | 26 +++++ ...2022_10_08_000006_create_capitals_table.js | 28 ++++++ ...2022_10_08_000007_create_students_table.js | 35 +++++++ .../2022_10_08_000008_create_courses_table.js | 35 +++++++ ...08_000009_create_students_courses_table.js | 37 ++++++++ database/seeders/UserSeeder.js | 13 +++ src/Facades/DB.js | 2 +- src/Facades/Database.js | 2 +- src/Providers/DatabaseProvider.js | 2 +- 20 files changed, 571 insertions(+), 3 deletions(-) create mode 100644 app/Console/Exceptions/Handler.js create mode 100644 app/Console/Kernel.js create mode 100644 app/Resources/UserResource.js create mode 100644 config/app.js create mode 100644 config/database.js create mode 100644 config/logging.js create mode 100644 database/migrations/2022_10_08_000000_create_uuid_function_postgres.js create mode 100644 database/migrations/2022_10_08_000001_create_users_mysql_table.js create mode 100644 database/migrations/2022_10_08_000002_create_products_mysql_table.js create mode 100644 database/migrations/2022_10_08_000003_create_users_postgres_table.js create mode 100644 database/migrations/2022_10_08_000004_create_products_postgres_table.js create mode 100644 database/migrations/2022_10_08_000005_create_countries_table.js create mode 100644 database/migrations/2022_10_08_000006_create_capitals_table.js create mode 100644 database/migrations/2022_10_08_000007_create_students_table.js create mode 100644 database/migrations/2022_10_08_000008_create_courses_table.js create mode 100644 database/migrations/2022_10_08_000009_create_students_courses_table.js create mode 100644 database/seeders/UserSeeder.js diff --git a/app/Console/Exceptions/Handler.js b/app/Console/Exceptions/Handler.js new file mode 100644 index 0000000..c801a7e --- /dev/null +++ b/app/Console/Exceptions/Handler.js @@ -0,0 +1,24 @@ +import { ConsoleExceptionHandler } from '@athenna/artisan' + +/* +|-------------------------------------------------------------------------- +| Console Exception Handler +|-------------------------------------------------------------------------- +| +| Athenna will forward all exceptions occurred during an Artisan command +| execution to the following class. You can learn more about exception +| handling by reading docs. +| +*/ + +export class Handler extends ConsoleExceptionHandler { + /** + * The global exception handler of all Artisan commands. + * + * @param {import('@athenna/common').Exception} error + * @return {Promise} + */ + async handle(error) { + return super.handle(error) + } +} diff --git a/app/Console/Kernel.js b/app/Console/Kernel.js new file mode 100644 index 0000000..e82cc0f --- /dev/null +++ b/app/Console/Kernel.js @@ -0,0 +1,21 @@ +/** + * @athenna/database + * + * (c) João Lenon + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { DatabaseLoader } from '#src/Helpers/DatabaseLoader' +import { ArtisanLoader, ConsoleKernel } from '@athenna/artisan' + +export class Kernel extends ConsoleKernel { + get commands() { + return [...ArtisanLoader.loadCommands(), ...DatabaseLoader.loadCommands()] + } + + get templates() { + return [...DatabaseLoader.loadTemplates()] + } +} diff --git a/app/Resources/UserResource.js b/app/Resources/UserResource.js new file mode 100644 index 0000000..071345c --- /dev/null +++ b/app/Resources/UserResource.js @@ -0,0 +1,15 @@ +import { Resource } from '#src/Models/Resource' + +export class UserResource extends Resource { + /** + * Set your object blueprint to execute in resources. + * + * @param object + * @return {any} + */ + static blueprint(object) { + return { + id: object.id, + } + } +} diff --git a/config/app.js b/config/app.js new file mode 100644 index 0000000..5a4a16d --- /dev/null +++ b/config/app.js @@ -0,0 +1,5 @@ +export default { + name: 'Artisan', + providers: [], + debug: true, +} diff --git a/config/database.js b/config/database.js new file mode 100644 index 0000000..aa1f369 --- /dev/null +++ b/config/database.js @@ -0,0 +1,95 @@ +export default { + /* + |-------------------------------------------------------------------------- + | Default Database Connection Name + |-------------------------------------------------------------------------- + | + | Here you may specify which of the database connections below you wish + | to use as your default connection for all database work. Of course + | you may use many connections at once using the Database library. + | + */ + default: 'postgres', + + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Athenna is shown below to make development simple. + | + */ + + connections: { + sqlite: { + driver: 'sqlite', + database: ':memory:', + synchronize: false, + }, + + mysql: { + driver: 'mysql', + host: '127.0.0.1', + port: 3307, + user: 'root', + password: '12345', + database: 'athenna', + debug: false, + synchronize: false, + }, + + postgres: { + driver: 'postgres', + host: 'localhost', + port: 5433, + user: 'postgres', + password: '12345', + database: 'postgres', + debug: false, + synchronize: true, + }, + + nullDriver: { + driver: 'notImplemented', + }, + + sqlserver: { + driver: 'sqlserver', + host: '127.0.0.1', + port: 1433, + user: 'sqlserver', + password: '12345', + database: 'sqlserver', + }, + + mongo: { + driver: 'mongo', + host: 'localhost', + port: 27018, + database: 'admin', + username: 'root', + password: '12345', + logging: ['error', 'warn'], + synchronize: false, + writeConcern: 'majority', + retryWrites: true, + useNewUrlParser: true, + useUnifiedTopology: true, + }, + }, + + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk haven't actually been run in the database. + | + */ + + migrations: 'migrations', +} diff --git a/config/logging.js b/config/logging.js new file mode 100644 index 0000000..456eb1a --- /dev/null +++ b/config/logging.js @@ -0,0 +1,48 @@ +export default { + /* + |-------------------------------------------------------------------------- + | Default Log Channel + |-------------------------------------------------------------------------- + | + | This option defines the default log channel that gets used when writing + | messages to the logs. The name specified in this option should match + | one of the channels defined in the "channels" configuration object. + | + */ + + default: 'console', + + /* + |-------------------------------------------------------------------------- + | Log Channels + |-------------------------------------------------------------------------- + | + | Here you may configure the log channels for your application. + | + | Available Drivers: + | "console", "discord", "file", "null", "slack", "telegram". + | Available Formatters: + | "cli", "simple", "json", "request", "message". + | + */ + + channels: { + application: { + driver: 'null', + formatter: 'simple', + }, + discard: { + driver: 'null', + }, + console: { + driver: 'null', + formatter: 'cli', + }, + exception: { + driver: 'console', + streamType: 'stderr', + + formatter: 'none', + }, + }, +} diff --git a/database/migrations/2022_10_08_000000_create_uuid_function_postgres.js b/database/migrations/2022_10_08_000000_create_uuid_function_postgres.js new file mode 100644 index 0000000..70c72d0 --- /dev/null +++ b/database/migrations/2022_10_08_000000_create_uuid_function_postgres.js @@ -0,0 +1,30 @@ +import { Migration } from '#src/index' + +export class UuidFunctionMigration extends Migration { + /** + * Create a table instance. + * + * @return {string} + */ + static get connection() { + return 'postgres' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up(knex) { + return knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"') + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down() {} +} diff --git a/database/migrations/2022_10_08_000001_create_users_mysql_table.js b/database/migrations/2022_10_08_000001_create_users_mysql_table.js new file mode 100644 index 0000000..7414f7a --- /dev/null +++ b/database/migrations/2022_10_08_000001_create_users_mysql_table.js @@ -0,0 +1,38 @@ +import { Migration } from '#src/index' + +export class UserMigration extends Migration { + /** + * Create a table instance. + * + * @return {string} + */ + static get connection() { + return 'mysql' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up({ schema }) { + return schema.createTable('users', table => { + table.increments('id') + table.string('name') + table.string('email').unique() + table.timestamps(true, true, true) + table.dateTime('deletedAt').nullable().defaultTo(null) + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('users') + } +} diff --git a/database/migrations/2022_10_08_000002_create_products_mysql_table.js b/database/migrations/2022_10_08_000002_create_products_mysql_table.js new file mode 100644 index 0000000..0294266 --- /dev/null +++ b/database/migrations/2022_10_08_000002_create_products_mysql_table.js @@ -0,0 +1,40 @@ +import { Migration } from '#src/index' + +export class ProductMigration extends Migration { + /** + * Create a table instance. + * + * @return {string} + */ + static get connection() { + return 'mysql' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up({ schema }) { + return schema.createTable('products', table => { + table.increments('id') + table.string('name', 255) + table.integer('price').defaultTo(0) + table.integer('userId').unsigned().index().references('id').inTable('users') + + table.timestamps(true, true, true) + table.dateTime('deletedAt').nullable().defaultTo(null) + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('products') + } +} diff --git a/database/migrations/2022_10_08_000003_create_users_postgres_table.js b/database/migrations/2022_10_08_000003_create_users_postgres_table.js new file mode 100644 index 0000000..8978b3f --- /dev/null +++ b/database/migrations/2022_10_08_000003_create_users_postgres_table.js @@ -0,0 +1,38 @@ +import { Migration } from '#src/index' + +export class UserMigration extends Migration { + /** + * Create a table instance. + * + * @return {string} + */ + static get connection() { + return 'postgres' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up({ schema }) { + return schema.createTable('users', table => { + table.increments('id') + table.string('name') + table.string('email').unique() + table.timestamps(true, true, true) + table.dateTime('deletedAt').nullable().defaultTo(null) + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('users') + } +} diff --git a/database/migrations/2022_10_08_000004_create_products_postgres_table.js b/database/migrations/2022_10_08_000004_create_products_postgres_table.js new file mode 100644 index 0000000..d9f793b --- /dev/null +++ b/database/migrations/2022_10_08_000004_create_products_postgres_table.js @@ -0,0 +1,40 @@ +import { Migration } from '#src/index' + +export class ProductMigration extends Migration { + /** + * Create a table instance. + * + * @return {string} + */ + static get connection() { + return 'postgres' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up({ schema }) { + return schema.createTable('products', table => { + table.increments('id') + table.string('name', 255) + table.integer('price').defaultTo(0) + table.integer('userId').unsigned().index().references('id').inTable('users') + + table.timestamps(true, true, true) + table.dateTime('deletedAt').nullable().defaultTo(null) + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('products') + } +} diff --git a/database/migrations/2022_10_08_000005_create_countries_table.js b/database/migrations/2022_10_08_000005_create_countries_table.js new file mode 100644 index 0000000..92da94a --- /dev/null +++ b/database/migrations/2022_10_08_000005_create_countries_table.js @@ -0,0 +1,26 @@ +import { Migration } from '#src/index' + +export class CountryMigration extends Migration { + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up(knex) { + return knex.schema.createTable('countries', table => { + table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()')) + table.string('name') + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('countries') + } +} diff --git a/database/migrations/2022_10_08_000006_create_capitals_table.js b/database/migrations/2022_10_08_000006_create_capitals_table.js new file mode 100644 index 0000000..a1ac5a5 --- /dev/null +++ b/database/migrations/2022_10_08_000006_create_capitals_table.js @@ -0,0 +1,28 @@ +import { Migration } from '#src/index' + +export class CapitalMigration extends Migration { + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up(knex) { + return knex.schema.createTable('capitals', table => { + table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()')) + table.string('name') + + table.uuid('countryId').unique().unsigned().index().references('id').inTable('countries') + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('capitals') + } +} diff --git a/database/migrations/2022_10_08_000007_create_students_table.js b/database/migrations/2022_10_08_000007_create_students_table.js new file mode 100644 index 0000000..136e8a7 --- /dev/null +++ b/database/migrations/2022_10_08_000007_create_students_table.js @@ -0,0 +1,35 @@ +import { Migration } from '#src/index' + +export class StudentMigration extends Migration { + /** + * Set the db connection that this model instance will work with. + * + * @return {string} + */ + static get connection() { + return 'mysql' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up(knex) { + return knex.schema.createTable('students', table => { + table.uuid('id').primary().defaultTo(knex.raw('(UUID())')) + table.string('name') + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('students') + } +} diff --git a/database/migrations/2022_10_08_000008_create_courses_table.js b/database/migrations/2022_10_08_000008_create_courses_table.js new file mode 100644 index 0000000..09224d9 --- /dev/null +++ b/database/migrations/2022_10_08_000008_create_courses_table.js @@ -0,0 +1,35 @@ +import { Migration } from '#src/index' + +export class CourseMigration extends Migration { + /** + * Set the db connection that this model instance will work with. + * + * @return {string} + */ + static get connection() { + return 'mysql' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up(knex) { + return knex.schema.createTable('courses', table => { + table.uuid('id').primary().defaultTo(knex.raw('(UUID())')) + table.string('name') + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('courses') + } +} diff --git a/database/migrations/2022_10_08_000009_create_students_courses_table.js b/database/migrations/2022_10_08_000009_create_students_courses_table.js new file mode 100644 index 0000000..84a60a1 --- /dev/null +++ b/database/migrations/2022_10_08_000009_create_students_courses_table.js @@ -0,0 +1,37 @@ +import { Migration } from '#src/index' + +export class StudentCourseMigration extends Migration { + /** + * Set the db connection that this model instance will work with. + * + * @return {string} + */ + static get connection() { + return 'mysql' + } + + /** + * Run the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async up(knex) { + return knex.schema.createTable('students_courses', table => { + table.uuid('id').primary().defaultTo(knex.raw('(UUID())')) + + table.uuid('courseId').references('id').inTable('courses') + table.uuid('studentId').references('id').inTable('students') + }) + } + + /** + * Reverse the migrations. + * + * @param {import('knex').Knex} knex + * @return {Promise} + */ + async down({ schema }) { + return schema.dropTableIfExists('students_courses') + } +} diff --git a/database/seeders/UserSeeder.js b/database/seeders/UserSeeder.js new file mode 100644 index 0000000..2497c6e --- /dev/null +++ b/database/seeders/UserSeeder.js @@ -0,0 +1,13 @@ +import { Seeder } from '#src/Database/Seeders/Seeder' +import { User } from '#tests/Stubs/models/User' + +export class UserSeeder extends Seeder { + /** + * Run the database seeders. + * + * @return {Promise} + */ + async run() { + await User.factory().count(10).create() + } +} diff --git a/src/Facades/DB.js b/src/Facades/DB.js index e2f9443..747bc7b 100644 --- a/src/Facades/DB.js +++ b/src/Facades/DB.js @@ -10,6 +10,6 @@ import { Facade } from '@athenna/ioc' /** - * @type {Facade & import('#src/index').Database} + * @type {Facade & import('#src/index').DatabaseImpl} */ export const DB = Facade.createFor('Athenna/Core/Database') diff --git a/src/Facades/Database.js b/src/Facades/Database.js index 2473803..2f94984 100644 --- a/src/Facades/Database.js +++ b/src/Facades/Database.js @@ -10,6 +10,6 @@ import { Facade } from '@athenna/ioc' /** - * @type {Facade & import('#src/index').Database} + * @type {Facade & import('#src/index').DatabaseImpl} */ export const Database = Facade.createFor('Athenna/Core/Database') diff --git a/src/Providers/DatabaseProvider.js b/src/Providers/DatabaseProvider.js index a698681..d646c24 100644 --- a/src/Providers/DatabaseProvider.js +++ b/src/Providers/DatabaseProvider.js @@ -22,7 +22,7 @@ export class DatabaseProvider extends ServiceProvider { .bind('Athenna/Core/Database', DatabaseImpl) .use('Athenna/Core/Database') - if (Env('DB_AUTO_CONNECT', true) && !Env('IS_ARTISAN', true)) { + if (Env('DB_AUTO_CONNECT', true)) { await Database.connect() } } From fa689bbdd8709faa1f74bbbbbda708e4364f00f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 27 Oct 2022 14:32:47 -0300 Subject: [PATCH 2/5] fix(structure): remove auto generated folders --- app/Console/Exceptions/Handler.js | 24 ----- app/Console/Kernel.js | 21 ---- app/Resources/UserResource.js | 15 --- config/app.js | 5 - config/database.js | 95 ------------------- config/logging.js | 48 ---------- ...08_000000_create_uuid_function_postgres.js | 30 ------ ...2_10_08_000001_create_users_mysql_table.js | 38 -------- ...0_08_000002_create_products_mysql_table.js | 40 -------- ...0_08_000003_create_users_postgres_table.js | 38 -------- ...8_000004_create_products_postgres_table.js | 40 -------- ...022_10_08_000005_create_countries_table.js | 26 ----- ...2022_10_08_000006_create_capitals_table.js | 28 ------ ...2022_10_08_000007_create_students_table.js | 35 ------- .../2022_10_08_000008_create_courses_table.js | 35 ------- ...08_000009_create_students_courses_table.js | 37 -------- database/seeders/UserSeeder.js | 13 --- 17 files changed, 568 deletions(-) delete mode 100644 app/Console/Exceptions/Handler.js delete mode 100644 app/Console/Kernel.js delete mode 100644 app/Resources/UserResource.js delete mode 100644 config/app.js delete mode 100644 config/database.js delete mode 100644 config/logging.js delete mode 100644 database/migrations/2022_10_08_000000_create_uuid_function_postgres.js delete mode 100644 database/migrations/2022_10_08_000001_create_users_mysql_table.js delete mode 100644 database/migrations/2022_10_08_000002_create_products_mysql_table.js delete mode 100644 database/migrations/2022_10_08_000003_create_users_postgres_table.js delete mode 100644 database/migrations/2022_10_08_000004_create_products_postgres_table.js delete mode 100644 database/migrations/2022_10_08_000005_create_countries_table.js delete mode 100644 database/migrations/2022_10_08_000006_create_capitals_table.js delete mode 100644 database/migrations/2022_10_08_000007_create_students_table.js delete mode 100644 database/migrations/2022_10_08_000008_create_courses_table.js delete mode 100644 database/migrations/2022_10_08_000009_create_students_courses_table.js delete mode 100644 database/seeders/UserSeeder.js diff --git a/app/Console/Exceptions/Handler.js b/app/Console/Exceptions/Handler.js deleted file mode 100644 index c801a7e..0000000 --- a/app/Console/Exceptions/Handler.js +++ /dev/null @@ -1,24 +0,0 @@ -import { ConsoleExceptionHandler } from '@athenna/artisan' - -/* -|-------------------------------------------------------------------------- -| Console Exception Handler -|-------------------------------------------------------------------------- -| -| Athenna will forward all exceptions occurred during an Artisan command -| execution to the following class. You can learn more about exception -| handling by reading docs. -| -*/ - -export class Handler extends ConsoleExceptionHandler { - /** - * The global exception handler of all Artisan commands. - * - * @param {import('@athenna/common').Exception} error - * @return {Promise} - */ - async handle(error) { - return super.handle(error) - } -} diff --git a/app/Console/Kernel.js b/app/Console/Kernel.js deleted file mode 100644 index e82cc0f..0000000 --- a/app/Console/Kernel.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @athenna/database - * - * (c) João Lenon - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -import { DatabaseLoader } from '#src/Helpers/DatabaseLoader' -import { ArtisanLoader, ConsoleKernel } from '@athenna/artisan' - -export class Kernel extends ConsoleKernel { - get commands() { - return [...ArtisanLoader.loadCommands(), ...DatabaseLoader.loadCommands()] - } - - get templates() { - return [...DatabaseLoader.loadTemplates()] - } -} diff --git a/app/Resources/UserResource.js b/app/Resources/UserResource.js deleted file mode 100644 index 071345c..0000000 --- a/app/Resources/UserResource.js +++ /dev/null @@ -1,15 +0,0 @@ -import { Resource } from '#src/Models/Resource' - -export class UserResource extends Resource { - /** - * Set your object blueprint to execute in resources. - * - * @param object - * @return {any} - */ - static blueprint(object) { - return { - id: object.id, - } - } -} diff --git a/config/app.js b/config/app.js deleted file mode 100644 index 5a4a16d..0000000 --- a/config/app.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - name: 'Artisan', - providers: [], - debug: true, -} diff --git a/config/database.js b/config/database.js deleted file mode 100644 index aa1f369..0000000 --- a/config/database.js +++ /dev/null @@ -1,95 +0,0 @@ -export default { - /* - |-------------------------------------------------------------------------- - | Default Database Connection Name - |-------------------------------------------------------------------------- - | - | Here you may specify which of the database connections below you wish - | to use as your default connection for all database work. Of course - | you may use many connections at once using the Database library. - | - */ - default: 'postgres', - - /* - |-------------------------------------------------------------------------- - | Database Connections - |-------------------------------------------------------------------------- - | - | Here are each of the database connections setup for your application. - | Of course, examples of configuring each database platform that is - | supported by Athenna is shown below to make development simple. - | - */ - - connections: { - sqlite: { - driver: 'sqlite', - database: ':memory:', - synchronize: false, - }, - - mysql: { - driver: 'mysql', - host: '127.0.0.1', - port: 3307, - user: 'root', - password: '12345', - database: 'athenna', - debug: false, - synchronize: false, - }, - - postgres: { - driver: 'postgres', - host: 'localhost', - port: 5433, - user: 'postgres', - password: '12345', - database: 'postgres', - debug: false, - synchronize: true, - }, - - nullDriver: { - driver: 'notImplemented', - }, - - sqlserver: { - driver: 'sqlserver', - host: '127.0.0.1', - port: 1433, - user: 'sqlserver', - password: '12345', - database: 'sqlserver', - }, - - mongo: { - driver: 'mongo', - host: 'localhost', - port: 27018, - database: 'admin', - username: 'root', - password: '12345', - logging: ['error', 'warn'], - synchronize: false, - writeConcern: 'majority', - retryWrites: true, - useNewUrlParser: true, - useUnifiedTopology: true, - }, - }, - - /* - |-------------------------------------------------------------------------- - | Migration Repository Table - |-------------------------------------------------------------------------- - | - | This table keeps track of all the migrations that have already run for - | your application. Using this information, we can determine which of - | the migrations on disk haven't actually been run in the database. - | - */ - - migrations: 'migrations', -} diff --git a/config/logging.js b/config/logging.js deleted file mode 100644 index 456eb1a..0000000 --- a/config/logging.js +++ /dev/null @@ -1,48 +0,0 @@ -export default { - /* - |-------------------------------------------------------------------------- - | Default Log Channel - |-------------------------------------------------------------------------- - | - | This option defines the default log channel that gets used when writing - | messages to the logs. The name specified in this option should match - | one of the channels defined in the "channels" configuration object. - | - */ - - default: 'console', - - /* - |-------------------------------------------------------------------------- - | Log Channels - |-------------------------------------------------------------------------- - | - | Here you may configure the log channels for your application. - | - | Available Drivers: - | "console", "discord", "file", "null", "slack", "telegram". - | Available Formatters: - | "cli", "simple", "json", "request", "message". - | - */ - - channels: { - application: { - driver: 'null', - formatter: 'simple', - }, - discard: { - driver: 'null', - }, - console: { - driver: 'null', - formatter: 'cli', - }, - exception: { - driver: 'console', - streamType: 'stderr', - - formatter: 'none', - }, - }, -} diff --git a/database/migrations/2022_10_08_000000_create_uuid_function_postgres.js b/database/migrations/2022_10_08_000000_create_uuid_function_postgres.js deleted file mode 100644 index 70c72d0..0000000 --- a/database/migrations/2022_10_08_000000_create_uuid_function_postgres.js +++ /dev/null @@ -1,30 +0,0 @@ -import { Migration } from '#src/index' - -export class UuidFunctionMigration extends Migration { - /** - * Create a table instance. - * - * @return {string} - */ - static get connection() { - return 'postgres' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up(knex) { - return knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"') - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down() {} -} diff --git a/database/migrations/2022_10_08_000001_create_users_mysql_table.js b/database/migrations/2022_10_08_000001_create_users_mysql_table.js deleted file mode 100644 index 7414f7a..0000000 --- a/database/migrations/2022_10_08_000001_create_users_mysql_table.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Migration } from '#src/index' - -export class UserMigration extends Migration { - /** - * Create a table instance. - * - * @return {string} - */ - static get connection() { - return 'mysql' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up({ schema }) { - return schema.createTable('users', table => { - table.increments('id') - table.string('name') - table.string('email').unique() - table.timestamps(true, true, true) - table.dateTime('deletedAt').nullable().defaultTo(null) - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('users') - } -} diff --git a/database/migrations/2022_10_08_000002_create_products_mysql_table.js b/database/migrations/2022_10_08_000002_create_products_mysql_table.js deleted file mode 100644 index 0294266..0000000 --- a/database/migrations/2022_10_08_000002_create_products_mysql_table.js +++ /dev/null @@ -1,40 +0,0 @@ -import { Migration } from '#src/index' - -export class ProductMigration extends Migration { - /** - * Create a table instance. - * - * @return {string} - */ - static get connection() { - return 'mysql' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up({ schema }) { - return schema.createTable('products', table => { - table.increments('id') - table.string('name', 255) - table.integer('price').defaultTo(0) - table.integer('userId').unsigned().index().references('id').inTable('users') - - table.timestamps(true, true, true) - table.dateTime('deletedAt').nullable().defaultTo(null) - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('products') - } -} diff --git a/database/migrations/2022_10_08_000003_create_users_postgres_table.js b/database/migrations/2022_10_08_000003_create_users_postgres_table.js deleted file mode 100644 index 8978b3f..0000000 --- a/database/migrations/2022_10_08_000003_create_users_postgres_table.js +++ /dev/null @@ -1,38 +0,0 @@ -import { Migration } from '#src/index' - -export class UserMigration extends Migration { - /** - * Create a table instance. - * - * @return {string} - */ - static get connection() { - return 'postgres' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up({ schema }) { - return schema.createTable('users', table => { - table.increments('id') - table.string('name') - table.string('email').unique() - table.timestamps(true, true, true) - table.dateTime('deletedAt').nullable().defaultTo(null) - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('users') - } -} diff --git a/database/migrations/2022_10_08_000004_create_products_postgres_table.js b/database/migrations/2022_10_08_000004_create_products_postgres_table.js deleted file mode 100644 index d9f793b..0000000 --- a/database/migrations/2022_10_08_000004_create_products_postgres_table.js +++ /dev/null @@ -1,40 +0,0 @@ -import { Migration } from '#src/index' - -export class ProductMigration extends Migration { - /** - * Create a table instance. - * - * @return {string} - */ - static get connection() { - return 'postgres' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up({ schema }) { - return schema.createTable('products', table => { - table.increments('id') - table.string('name', 255) - table.integer('price').defaultTo(0) - table.integer('userId').unsigned().index().references('id').inTable('users') - - table.timestamps(true, true, true) - table.dateTime('deletedAt').nullable().defaultTo(null) - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('products') - } -} diff --git a/database/migrations/2022_10_08_000005_create_countries_table.js b/database/migrations/2022_10_08_000005_create_countries_table.js deleted file mode 100644 index 92da94a..0000000 --- a/database/migrations/2022_10_08_000005_create_countries_table.js +++ /dev/null @@ -1,26 +0,0 @@ -import { Migration } from '#src/index' - -export class CountryMigration extends Migration { - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up(knex) { - return knex.schema.createTable('countries', table => { - table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()')) - table.string('name') - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('countries') - } -} diff --git a/database/migrations/2022_10_08_000006_create_capitals_table.js b/database/migrations/2022_10_08_000006_create_capitals_table.js deleted file mode 100644 index a1ac5a5..0000000 --- a/database/migrations/2022_10_08_000006_create_capitals_table.js +++ /dev/null @@ -1,28 +0,0 @@ -import { Migration } from '#src/index' - -export class CapitalMigration extends Migration { - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up(knex) { - return knex.schema.createTable('capitals', table => { - table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()')) - table.string('name') - - table.uuid('countryId').unique().unsigned().index().references('id').inTable('countries') - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('capitals') - } -} diff --git a/database/migrations/2022_10_08_000007_create_students_table.js b/database/migrations/2022_10_08_000007_create_students_table.js deleted file mode 100644 index 136e8a7..0000000 --- a/database/migrations/2022_10_08_000007_create_students_table.js +++ /dev/null @@ -1,35 +0,0 @@ -import { Migration } from '#src/index' - -export class StudentMigration extends Migration { - /** - * Set the db connection that this model instance will work with. - * - * @return {string} - */ - static get connection() { - return 'mysql' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up(knex) { - return knex.schema.createTable('students', table => { - table.uuid('id').primary().defaultTo(knex.raw('(UUID())')) - table.string('name') - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('students') - } -} diff --git a/database/migrations/2022_10_08_000008_create_courses_table.js b/database/migrations/2022_10_08_000008_create_courses_table.js deleted file mode 100644 index 09224d9..0000000 --- a/database/migrations/2022_10_08_000008_create_courses_table.js +++ /dev/null @@ -1,35 +0,0 @@ -import { Migration } from '#src/index' - -export class CourseMigration extends Migration { - /** - * Set the db connection that this model instance will work with. - * - * @return {string} - */ - static get connection() { - return 'mysql' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up(knex) { - return knex.schema.createTable('courses', table => { - table.uuid('id').primary().defaultTo(knex.raw('(UUID())')) - table.string('name') - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('courses') - } -} diff --git a/database/migrations/2022_10_08_000009_create_students_courses_table.js b/database/migrations/2022_10_08_000009_create_students_courses_table.js deleted file mode 100644 index 84a60a1..0000000 --- a/database/migrations/2022_10_08_000009_create_students_courses_table.js +++ /dev/null @@ -1,37 +0,0 @@ -import { Migration } from '#src/index' - -export class StudentCourseMigration extends Migration { - /** - * Set the db connection that this model instance will work with. - * - * @return {string} - */ - static get connection() { - return 'mysql' - } - - /** - * Run the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async up(knex) { - return knex.schema.createTable('students_courses', table => { - table.uuid('id').primary().defaultTo(knex.raw('(UUID())')) - - table.uuid('courseId').references('id').inTable('courses') - table.uuid('studentId').references('id').inTable('students') - }) - } - - /** - * Reverse the migrations. - * - * @param {import('knex').Knex} knex - * @return {Promise} - */ - async down({ schema }) { - return schema.dropTableIfExists('students_courses') - } -} diff --git a/database/seeders/UserSeeder.js b/database/seeders/UserSeeder.js deleted file mode 100644 index 2497c6e..0000000 --- a/database/seeders/UserSeeder.js +++ /dev/null @@ -1,13 +0,0 @@ -import { Seeder } from '#src/Database/Seeders/Seeder' -import { User } from '#tests/Stubs/models/User' - -export class UserSeeder extends Seeder { - /** - * Run the database seeders. - * - * @return {Promise} - */ - async run() { - await User.factory().count(10).create() - } -} From cdeb78b8abb1c1c3b037a421df67a7bf93456b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 27 Oct 2022 14:35:18 -0300 Subject: [PATCH 3/5] chore(npm): update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40cbae5..d4671b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/database", - "version": "1.2.5", + "version": "1.2.6", "description": "The Athenna database handler for SQL/NoSQL.", "license": "MIT", "author": "João Lenon ", From b4a9621e00c0beeaca7f244785c09f0ad82da336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 27 Oct 2022 14:37:54 -0300 Subject: [PATCH 4/5] chore(npm): update version --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 41f4552..501e7dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/database", - "version": "1.2.5", + "version": "1.2.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/database", - "version": "1.2.5", + "version": "1.2.6", "license": "MIT", "dependencies": { "@athenna/artisan": "1.5.8", From d025d700d909dd31c5ec4f1346a14c0b60af0ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Thu, 27 Oct 2022 14:39:34 -0300 Subject: [PATCH 5/5] chore(npm): add keywords to package json --- package.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d4671b0..e049002 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,18 @@ "homepage": "https://github.com/AthennaIO/Database#readme", "keywords": [ "esm", - "athenna" + "orm", + "nodejs", + "athenna", + "database", + "migrations", + "factories", + "seeders", + "mysql", + "mongodb", + "postgresql", + "sql", + "nosql" ], "scripts": { "lint:fix": "eslint \"{src,tests}/**/*.js\" --fix",