Added database, orm, auth modules

added db migrations for users and initial data
added first controllers
added auth middleware
added rest routes and controller stub
...
This commit is contained in:
Sockenklaus
2023-07-03 16:24:19 +02:00
parent f58c0c3245
commit a52c0143df
21 changed files with 459 additions and 12 deletions

View File

@@ -0,0 +1,25 @@
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
export default class extends BaseSchema {
protected tableName = 'users'
public async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id').primary()
table.string('username', 255).notNullable().unique()
table.string('password', 180).notNullable()
table.string('remember_me_token').nullable()
table.boolean('is_admin').notNullable().defaultTo(false)
/**
* Uses timestampz for PostgreSQL and DATETIME2 for MSSQL
*/
table.timestamp('created_at', { useTz: true }).notNullable()
table.timestamp('updated_at', { useTz: true }).notNullable()
})
}
public async down() {
this.schema.dropTable(this.tableName)
}
}

18
database/seeders/User.ts Normal file
View File

@@ -0,0 +1,18 @@
import BaseSeeder from '@ioc:Adonis/Lucid/Seeder'
import User from 'App/Models/User'
export default class extends BaseSeeder {
public async run () {
await User.createMany([
{
username: 'admin',
password: 'initialPass',
isAdmin: true
},
{
username: "firstUser",
password: "firstPass",
}
])
}
}