Skip to content

Commit 9424c4e

Browse files
committed
fix(action): database
1 parent e1db4a5 commit 9424c4e

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

bin/test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assert } from '@japa/assert'
22
import { expectTypeOf } from '@japa/expect-type'
33
import { processCLIArgs, configure, run } from '@japa/runner'
4-
import { createApp } from '../tests/helpers/app.js'
4+
import { createApp, initializeDatabase } from '../tests/helpers/app.js'
55
import { fileSystem } from '@japa/file-system'
66
import app from '@adonisjs/core/services/app'
77
import { ApplicationService } from '@adonisjs/core/types'
@@ -15,6 +15,7 @@ configure({
1515
setup: [
1616
async () => {
1717
testApp = await createApp()
18+
await initializeDatabase(testApp)
1819
},
1920
],
2021
teardown: [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @jrmc/adonis-attachment
3+
*
4+
* @license MIT
5+
* @copyright Jeremy Chaufourier <[email protected]>
6+
*/
7+
import { BaseSchema } from '@adonisjs/lucid/schema'
8+
export default class extends BaseSchema {
9+
protected tableName = 'users'
10+
async up() {
11+
this.schema.createTable(this.tableName, (table) => {
12+
table.increments('id')
13+
table.string('name')
14+
table.json('avatar')
15+
table.json('avatar_2')
16+
table.timestamp('created_at')
17+
table.timestamp('updated_at')
18+
})
19+
}
20+
async down() {
21+
this.schema.dropTable(this.tableName)
22+
}
23+
}

tests/helpers/app.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
* @copyright Jeremy Chaufourier <[email protected]>
66
*/
77

8+
import type { ApplicationService } from '@adonisjs/core/types'
9+
import type { InferConverters } from '../../src/types/config.js'
10+
11+
import { copyFile, mkdir } from 'node:fs/promises'
812
import { IgnitorFactory } from '@adonisjs/core/factories'
913
import { defineConfig as defineLucidConfig } from '@adonisjs/lucid'
1014
import { defineConfig } from '../../src/define_config.js'
1115
import { defineConfig as defineDriveConfig, services } from '@adonisjs/drive'
1216

1317
import { BASE_URL } from './index.js'
14-
import type { InferConverters } from '../../src/types/config.js'
1518

1619
const IMPORTER = (filePath: string) => {
1720
if (filePath.startsWith('./') || filePath.startsWith('../')) {
@@ -83,7 +86,7 @@ export async function createApp(options = {}) {
8386
sqlite: {
8487
client: 'better-sqlite3',
8588
connection: {
86-
filename: new URL('./db.sqlite', BASE_URL).pathname,
89+
filename: new URL('../db.sqlite', BASE_URL).pathname,
8790
},
8891
},
8992
},
@@ -100,14 +103,21 @@ export async function createApp(options = {}) {
100103
await app.init()
101104
await app.boot()
102105

106+
await mkdir(app.migrationsPath(), { recursive: true })
107+
108+
await copyFile(
109+
new URL('../fixtures/migrations/create_users_table.ts', import.meta.url),
110+
app.migrationsPath('create_users_table.ts')
111+
)
112+
103113
return app
104114
}
105115

106-
// export async function initializeDatabase(app: ApplicationService) {
107-
// const ace = await app.container.make('ace')
108-
// await ace.exec('migration:fresh', [])
109-
// await seedDatabase()
110-
// }
116+
export async function initializeDatabase(app: ApplicationService) {
117+
const ace = await app.container.make('ace')
118+
await ace.exec('migration:fresh', [])
119+
// await seedDatabase()
120+
}
111121

112122
// async function seedDatabase() {
113123
// const { default: User } = await import('./fixtures/models/user.js')

0 commit comments

Comments
 (0)