Skip to content

Commit

Permalink
Merge branch 'adonisjs:develop' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush123 authored Sep 1, 2024
2 parents 6ad60af + cbbb4fd commit 24734bd
Show file tree
Hide file tree
Showing 76 changed files with 2,658 additions and 703 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
SQL ORM for AdonisJS built on top of Knex. Comes with a db query builder, Active record ORM, migrations, seeders and model factories.

## Official Documentation
The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/database/introduction)
The documentation is available on the [Lucid website](https://lucid.adonisjs.com/docs/introduction)

## Contributing
One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
Expand All @@ -19,7 +19,7 @@ We encourage you to read the [contribution guide](https://github.com/adonisjs/.g
Easiest way to run tests is to launch the redis cluster using docker-compose and `docker-compose.yml` file.

```sh
docker-compose up
docker-compose up -d
npm run test
```

Expand Down
2 changes: 1 addition & 1 deletion commands/db_seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class DbSeed extends BaseCommand {
break
case 'ignored':
message = 'ignored '
prefix = 'Enabled only in development environment'
prefix = `Disabled in "${this.app.getEnvironment()}" environment`
color = 'dim'
break
case 'completed':
Expand Down
4 changes: 2 additions & 2 deletions commands/db_truncate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class DbTruncate extends BaseCommand {
/**
* Prompts to take consent when truncating the database in production
*/
private async takeProductionConstent(): Promise<boolean> {
private async takeProductionConsent(): Promise<boolean> {
const question = 'You are in production environment. Want to continue truncating the database?'
try {
return await this.prompt.confirm(question)
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class DbTruncate extends BaseCommand {
*/
let continueTruncate = !this.app.inProduction || this.force
if (!continueTruncate) {
continueTruncate = await this.takeProductionConstent()
continueTruncate = await this.takeProductionConsent()
}

/**
Expand Down
27 changes: 25 additions & 2 deletions commands/db_wipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export default class DbWipe extends BaseCommand {
@flags.boolean({ description: 'Drop all custom types (Postgres only)' })
declare dropTypes: boolean

/**
* Drop all domains in database
*/
@flags.boolean({ description: 'Drop all domains (Postgres only)' })
declare dropDomains: boolean

/**
* Force command execution in production
*/
Expand All @@ -55,7 +61,7 @@ export default class DbWipe extends BaseCommand {
/**
* Prompts to take consent when wiping the database in production
*/
private async takeProductionConstent(): Promise<boolean> {
private async takeProductionConsent(): Promise<boolean> {
const question = 'You are in production environment. Want to continue wiping the database?'
try {
return await this.prompt.confirm(question)
Expand Down Expand Up @@ -104,6 +110,22 @@ export default class DbWipe extends BaseCommand {
this.logger.success('Dropped types successfully')
}

/**
* Drop all domains (if asked for and supported)
*/
private async performDropDomains(client: QueryClientContract, schemas: string[]) {
if (!this.dropDomains) {
return
}

if (!client.dialect.supportsDomains) {
this.logger.warning(`Dropping domains is not supported by "${client.dialect.name}"`)
}

await client.dropAllDomains(schemas)
this.logger.success('Dropped domains successfully')
}

/**
* Run as a subcommand. Never close database connections or exit
* process inside this method
Expand All @@ -119,7 +141,7 @@ export default class DbWipe extends BaseCommand {
*/
let continueWipe = !this.app.inProduction || this.force
if (!continueWipe) {
continueWipe = await this.takeProductionConstent()
continueWipe = await this.takeProductionConsent()
}

/**
Expand Down Expand Up @@ -147,6 +169,7 @@ export default class DbWipe extends BaseCommand {
await this.performDropViews(connection, schemas)
await this.performDropTables(connection, schemas)
await this.performDropTypes(connection, schemas)
await this.performDropDomains(connection, schemas)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion commands/migration/_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default abstract class MigrationsBase extends BaseCommand {
/**
* Prompts to take consent for running migrations in production
*/
protected async takeProductionConstent(): Promise<boolean> {
protected async takeProductionConsent(): Promise<boolean> {
const question = 'You are in production environment. Want to continue running migrations?'
try {
return await this.prompt.confirm(question)
Expand Down
14 changes: 12 additions & 2 deletions commands/migration/fresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export default class Refresh extends BaseCommand {
@flags.boolean({ description: 'Drop all custom types (Postgres only)' })
declare dropTypes: boolean

/**
* Drop all domains in database
*/
@flags.boolean({ description: 'Drop all domains (Postgres only)' })
declare dropDomains: boolean

/**
* Disable advisory locks
*/
Expand All @@ -67,7 +73,7 @@ export default class Refresh extends BaseCommand {
}

if (this.connection) {
args.push(`--connection="${this.connection}"`)
args.push(`--connection=${this.connection}`)
}

if (this.disableLocks) {
Expand All @@ -86,6 +92,10 @@ export default class Refresh extends BaseCommand {
args.push('--drop-types')
}

if (this.dropDomains) {
args.push('--drop-domains')
}

if (this.dropViews) {
args.push('--drop-views')
}
Expand Down Expand Up @@ -117,7 +127,7 @@ export default class Refresh extends BaseCommand {
private async runDbSeed() {
const args: string[] = []
if (this.connection) {
args.push(`--connection="${this.connection}"`)
args.push(`--connection=${this.connection}`)
}

const dbSeed = await this.kernel.exec('db:seed', args)
Expand Down
4 changes: 2 additions & 2 deletions commands/migration/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class Refresh extends BaseCommand {
}

if (this.connection) {
args.push(`--connection="${this.connection}"`)
args.push(`--connection=${this.connection}`)
}

if (this.dryRun) {
Expand Down Expand Up @@ -99,7 +99,7 @@ export default class Refresh extends BaseCommand {
private async runDbSeed() {
const args: string[] = []
if (this.connection) {
args.push(`--connection="${this.connection}"`)
args.push(`--connection=${this.connection}`)
}

const dbSeed = await this.kernel.exec('db:seed', args)
Expand Down
2 changes: 1 addition & 1 deletion commands/migration/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class Reset extends BaseCommand {
}

if (this.connection) {
args.push(`--connection="${this.connection}"`)
args.push(`--connection=${this.connection}`)
}

if (this.dryRun) {
Expand Down
15 changes: 12 additions & 3 deletions commands/migration/rollback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CommandOptions } from '@adonisjs/core/types/ace'
* The command is meant to migrate the database by executing migrations
* in `down` direction.
*/
export default class Migrate extends MigrationsBase {
export default class Rollback extends MigrationsBase {
static commandName = 'migration:rollback'
static description = 'Rollback migrations to a specific batch number'
static options: CommandOptions = {
Expand All @@ -35,7 +35,7 @@ export default class Migrate extends MigrationsBase {
/**
* Force run migrations in production
*/
@flags.boolean({ description: 'Explictly force to run migrations in production' })
@flags.boolean({ description: 'Explicitly force to run migrations in production' })
declare force: boolean

/**
Expand All @@ -52,6 +52,14 @@ export default class Migrate extends MigrationsBase {
})
declare batch: number

/**
* Define custom step, instead of rolling back to the latest batch
*/
@flags.number({
description: 'The number of migrations to be reverted',
})
declare step: number

/**
* Display migrations result in one compact single-line output
*/
Expand All @@ -74,6 +82,7 @@ export default class Migrate extends MigrationsBase {
direction: 'down',
connectionName: this.connection,
batch: this.batch,
step: this.step,
dryRun: this.dryRun,
disableLocks: this.disableLocks,
})
Expand All @@ -93,7 +102,7 @@ export default class Migrate extends MigrationsBase {
*/
let continueMigrations = !this.app.inProduction || this.force
if (!continueMigrations) {
continueMigrations = await this.takeProductionConstent()
continueMigrations = await this.takeProductionConsent()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion commands/migration/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class Migrate extends MigrationsBase {
*/
let continueMigrations = !this.app.inProduction || this.force
if (!continueMigrations) {
continueMigrations = await this.takeProductionConstent()
continueMigrations = await this.takeProductionConsent()
}

/**
Expand Down
6 changes: 2 additions & 4 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
legacy_mysql:
platform: linux/x86_64
Expand Down Expand Up @@ -48,7 +46,7 @@ services:
- $LEGACY_MYSQL_READ_REPLICA_PORT

pg:
image: postgres:11
image: postgres:16
container_name: pg
env_file: ./.env
environment:
Expand All @@ -61,7 +59,7 @@ services:
- $PG_PORT

pg_read_replica:
image: postgres:11
image: postgres:16
container_name: pg_read_replica
env_file: ./.env
environment:
Expand Down
9 changes: 7 additions & 2 deletions configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export async function configure(command: Configure) {
if (dialect === undefined) {
dialect = await command.prompt.choice(
'Select the database you want to use',
Object.keys(DIALECTS),
Object.keys(DIALECTS).map((dialectKey) => {
return {
name: dialectKey,
message: DIALECTS[dialectKey as keyof typeof DIALECTS].name,
}
}),
{
validate(value) {
return !!value
Expand All @@ -38,7 +43,7 @@ export async function configure(command: Configure) {
* Show error when selected dialect is not supported
*/
if (dialect! in DIALECTS === false) {
command.error(
command.logger.error(
`The selected database "${dialect}" is invalid. Select one from: ${string.sentence(
Object.keys(DIALECTS)
)}`
Expand Down
Loading

0 comments on commit 24734bd

Please sign in to comment.