mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-21 15:31:35 +01:00
initital commit
This commit is contained in:
1
database/factories/index.ts
Normal file
1
database/factories/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
// import Factory from '@ioc:Adonis/Lucid/Factory'
|
||||
18
database/migrations/1603020084373_subscribers.ts
Normal file
18
database/migrations/1603020084373_subscribers.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||
|
||||
export default class Subscribers extends BaseSchema {
|
||||
protected tableName = 'subscribers'
|
||||
|
||||
public async up () {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.increments('id').primary()
|
||||
table.string('name')
|
||||
table.string('email').notNullable()
|
||||
table.timestamps(true)
|
||||
})
|
||||
}
|
||||
|
||||
public async down () {
|
||||
this.schema.dropTable(this.tableName)
|
||||
}
|
||||
}
|
||||
34
database/migrations/1605093034793_users.ts
Normal file
34
database/migrations/1605093034793_users.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||
|
||||
export default class UsersSchema extends BaseSchema {
|
||||
protected tableName = 'users'
|
||||
|
||||
public async up () {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.increments('id').primary()
|
||||
table.string('email', 255).notNullable()
|
||||
table.string('password', 180).defaultTo(this.randomPassword()).notNullable()
|
||||
table.boolean('is_confirmed').defaultTo(false).notNullable()
|
||||
table.string('remember_me_token').defaultTo(null).nullable()
|
||||
table.string('confirmation_token').defaultTo(null).nullable()
|
||||
table.timestamps(true)
|
||||
})
|
||||
}
|
||||
|
||||
private randomPassword () {
|
||||
let chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
let password = ''
|
||||
let passwordLength = 12
|
||||
|
||||
for (let i = 0; i < passwordLength; i++) {
|
||||
let rnum = Math.floor(Math.random() * chars.length);
|
||||
password += chars.substring(rnum,rnum+1);
|
||||
}
|
||||
|
||||
return password
|
||||
}
|
||||
|
||||
public async down () {
|
||||
this.schema.dropTable(this.tableName)
|
||||
}
|
||||
}
|
||||
25
database/migrations/1605093087010_api_tokens.ts
Normal file
25
database/migrations/1605093087010_api_tokens.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||
|
||||
export default class ApiTokens extends BaseSchema {
|
||||
protected tableName = 'api_tokens'
|
||||
|
||||
public async up () {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.increments('id').primary()
|
||||
table.integer('user_id').unsigned().references('id').inTable('users').onDelete('CASCADE')
|
||||
table.string('name').notNullable()
|
||||
table.string('type').notNullable()
|
||||
table.string('token', 64).notNullable()
|
||||
|
||||
/**
|
||||
* "useTz: true" utilizes timezone option in PostgreSQL and MSSQL
|
||||
*/
|
||||
table.timestamp('expires_at', { useTz: true }).nullable()
|
||||
table.timestamp('created_at', { useTz: true }).notNullable()
|
||||
})
|
||||
}
|
||||
|
||||
public async down () {
|
||||
this.schema.dropTable(this.tableName)
|
||||
}
|
||||
}
|
||||
18
database/migrations/1605956543449_files.ts
Normal file
18
database/migrations/1605956543449_files.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||
|
||||
export default class Pictures extends BaseSchema {
|
||||
protected tableName = 'files'
|
||||
|
||||
public async up () {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.increments('id').primary()
|
||||
table.string('label').notNullable()
|
||||
table.string('file_name').notNullable()
|
||||
table.timestamps(true)
|
||||
})
|
||||
}
|
||||
|
||||
public async down () {
|
||||
this.schema.dropTable(this.tableName)
|
||||
}
|
||||
}
|
||||
18
database/migrations/1605956711010_posts.ts
Normal file
18
database/migrations/1605956711010_posts.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||
|
||||
export default class Posts extends BaseSchema {
|
||||
protected tableName = 'posts'
|
||||
|
||||
public async up () {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.increments('id').primary()
|
||||
table.string('slug').notNullable()
|
||||
table.integer('likes').notNullable()
|
||||
table.timestamps(true)
|
||||
})
|
||||
}
|
||||
|
||||
public async down () {
|
||||
this.schema.dropTable(this.tableName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user