Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set properties for make:migration #102

Merged
merged 2 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 16 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/database",
"version": "4.6.0",
"version": "4.6.1",
"description": "The Athenna database handler for SQL/NoSQL.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
16 changes: 14 additions & 2 deletions src/commands/MakeMigrationCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export class MakeMigrationCommand extends BaseCommand {
public async handle(): Promise<void> {
this.logger.simple('({bold,green} [ MAKING MIGRATION ])\n')

const nameUp = this.name.toUpperCase()
const nameCamel = String.toCamelCase(this.name)
const namePlural = String.pluralize(this.name)
const namePascal = String.toPascalCase(this.name)
const namePluralCamel = String.toCamelCase(String.pluralize(this.name))
const namePluralPascal = String.toPascalCase(String.pluralize(this.name))

this.tableName = String.pluralize(
namePascal
Expand All @@ -41,9 +46,16 @@ export class MakeMigrationCommand extends BaseCommand {

const file = await this.generator
.path(this.getFilePath())
.properties({ nameTable: this.tableName })
.properties({
nameUp,
nameCamel,
namePlural,
namePascal,
namePluralCamel,
namePluralPascal,
tableName: this.tableName
})
.template('migration')
.setNameProperties(true)
.make()

this.logger.success(
Expand Down
2 changes: 1 addition & 1 deletion templates/migration.edge
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseMigration, type DatabaseImpl } from '@athenna/database'

export class {{ namePascal }} extends BaseMigration {
public tableName = '{{ nameTable }}'
public tableName = '{{ tableName }}'

public async up(db: DatabaseImpl) {
return db.createTable(this.tableName, builder => {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/configurer/DatabaseConfigurerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class DatabaseConfigurerTest {
assert.isTrue(await File.exists(Path.pwd('config/database.ts')))
assert.deepEqual(
dockerComposeFile,
'version: "3"\n\nservices:\n mysql:\n container_name: athenna_mysql\n image: mysql\n ports:\n - "3306:3306"\n environment:\n MYSQL_DATABASE: athenna\n MYSQL_ROOT_PASSWORD: root\n MYSQL_ALLOW_EMPTY_PASSWORD: \'yes\'\n'
"version: '3'\n\nservices:\n mysql:\n container_name: athenna_mysql\n image: mysql\n ports:\n - '3306:3306'\n environment:\n MYSQL_DATABASE: athenna\n MYSQL_ROOT_PASSWORD: root\n MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'\n"
)
assert.deepEqual(
envFile,
Expand Down Expand Up @@ -116,7 +116,7 @@ export default class DatabaseConfigurerTest {
assert.isTrue(await File.exists(Path.pwd('config/database.ts')))
assert.deepEqual(
dockerComposeFile,
'version: "3"\n\nservices:\n postgres:\n container_name: athenna_postgres\n image: postgres\n ports:\n - "5432:5432"\n environment:\n POSTGRES_DB: postgres\n POSTGRES_USER: postgres\n POSTGRES_PASSWORD: 12345\n POSTGRES_ROOT_PASSWORD: 12345\n'
"version: '3'\n\nservices:\n postgres:\n container_name: athenna_postgres\n image: postgres\n ports:\n - '5432:5432'\n environment:\n POSTGRES_DB: athenna\n POSTGRES_USER: root\n POSTGRES_PASSWORD: root\n POSTGRES_ROOT_PASSWORD: root\n"
)
assert.deepEqual(
envFile,
Expand Down Expand Up @@ -182,7 +182,7 @@ export default class DatabaseConfigurerTest {
assert.isTrue(await File.exists(Path.pwd('config/database.ts')))
assert.deepEqual(
dockerComposeFile,
'version: "3"\n\nservices:\n mongo:\n container_name: athenna_mongo\n image: mongo\n ports:\n - "27017:27017"\n environment:\n MONGO_INITDB_ROOT_USERNAME: root\n MONGO_INITDB_ROOT_PASSWORD: root\n'
"version: '3'\n\nservices:\n mongo:\n container_name: athenna_mongo\n image: mongo\n ports:\n - '27017:27017'\n environment:\n MONGO_INITDB_ROOT_USERNAME: root\n MONGO_INITDB_ROOT_PASSWORD: root\n"
)
assert.deepEqual(envFile, `\nDB_CONNECTION=mongo\n` + 'DB_URL=mongodb://root:root@localhost:27017/athenna\n')
}
Expand Down
Loading