-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dfeac1
commit 702ae0b
Showing
12 changed files
with
243 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DateTime } from 'luxon' | ||
import { BaseModel, column, belongsTo, BelongsTo } from '@ioc:Adonis/Lucid/Orm' | ||
import User from './User' | ||
|
||
export default class Channel extends BaseModel { | ||
@column({ isPrimary: true }) | ||
public id: number | ||
|
||
@column() | ||
public name: string | ||
|
||
@belongsTo(() => User) | ||
public owner: BelongsTo<typeof User> | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
public createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
public updatedAt: DateTime | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DateTime } from 'luxon' | ||
import { BaseModel, belongsTo, BelongsTo, column } from '@ioc:Adonis/Lucid/Orm' | ||
import Channel from './Channel' | ||
import User from './User' | ||
|
||
export default class Message extends BaseModel { | ||
@column({ isPrimary: true }) | ||
public id: number | ||
|
||
@column() | ||
public content: string | ||
|
||
@belongsTo(() => User) | ||
public user: BelongsTo<typeof User> | ||
|
||
@belongsTo(() => Channel) | ||
public channel: BelongsTo<typeof Channel> | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
public createdAt: DateTime | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { DateTime } from 'luxon' | ||
import Hash from '@ioc:Adonis/Core/Hash' | ||
import { column, beforeSave, BaseModel, manyToMany, ManyToMany } from '@ioc:Adonis/Lucid/Orm' | ||
import Channel from './Channel' | ||
|
||
export default class User extends BaseModel { | ||
@column({ isPrimary: true }) | ||
public id: number | ||
|
||
@column() | ||
public email: string | ||
|
||
@column() | ||
public firstName: string | ||
|
||
@column() | ||
public lastName: string | ||
|
||
@column() | ||
public nickName: string | ||
|
||
@column({ serializeAs: null }) | ||
public password: string | ||
|
||
@column() | ||
public rememberMeToken?: string | ||
|
||
@column.dateTime({ autoCreate: true }) | ||
public createdAt: DateTime | ||
|
||
@column.dateTime({ autoCreate: true, autoUpdate: true }) | ||
public updatedAt: DateTime | ||
|
||
@manyToMany(() => Channel, { | ||
pivotTable: 'channel_users', | ||
pivotForeignKey: 'user_id', | ||
pivotRelatedForeignKey: 'channel_id', | ||
pivotTimestamps: true, | ||
}) | ||
public channels: ManyToMany<typeof Channel> | ||
|
||
@manyToMany(() => User, { | ||
pivotTable: 'invites', | ||
pivotForeignKey: 'to_user_id', | ||
pivotRelatedForeignKey: 'channel_id', | ||
pivotTimestamps: true, | ||
}) | ||
public invites: ManyToMany<typeof User> | ||
|
||
@manyToMany(() => User, { | ||
pivotTable: 'kicks', | ||
pivotForeignKey: 'to_user_id', | ||
pivotRelatedForeignKey: 'channel_id', | ||
pivotTimestamps: true, | ||
}) | ||
public kicks: ManyToMany<typeof User> | ||
|
||
@beforeSave() | ||
public static async hashPassword (user: User) { | ||
if (user.$dirty.password) { | ||
user.password = await Hash.make(user.password) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
7 changes: 5 additions & 2 deletions
7
...atabase/migrations/1648629850794_auths.ts → ...atabase/migrations/1649074022865_users.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class Channels extends BaseSchema { | ||
protected tableName = 'channels' | ||
|
||
public async up () { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id').primary() | ||
table.string('name', 255).notNullable() | ||
|
||
table.integer("owner").notNullable().references("id").inTable("users").onDelete("CASCADE") | ||
/** | ||
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL | ||
*/ | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class Messages extends BaseSchema { | ||
protected tableName = 'messages' | ||
|
||
public async up () { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id').primary() | ||
table.string("content", 8095).notNullable() | ||
table.integer("user").notNullable().references("id").inTable("users") | ||
table.integer("channel").notNullable().references("id").inTable("channels").onDelete("CASCADE") | ||
/** | ||
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL | ||
*/ | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
adonisApi/database/migrations/1649083609099_channel_users.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class ChannelUsers extends BaseSchema { | ||
protected tableName = 'channel_users' | ||
|
||
public async up () { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id').primary() | ||
|
||
table.integer('user_id').unsigned().notNullable() | ||
.references('id').inTable('users').onDelete('CASCADE') | ||
table.integer('channel_id').unsigned().notNullable() | ||
.references('id').inTable('channels').onDelete('CASCADE') | ||
table.string("status", 255).notNullable() | ||
|
||
/** | ||
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL | ||
*/ | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
|
||
table.unique(['user_id', 'channel_id']) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class Invites extends BaseSchema { | ||
protected tableName = 'invites' | ||
|
||
public async up () { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id').primary() | ||
|
||
table.integer('from_user_id').unsigned().notNullable() | ||
.references('id').inTable('users').onDelete('CASCADE') | ||
table.integer('to_user_id').unsigned().notNullable() | ||
.references('id').inTable('users').onDelete('CASCADE') | ||
table.integer('channel_id').unsigned().notNullable() | ||
.references('id').inTable('channels').onDelete('CASCADE') | ||
|
||
/** | ||
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL | ||
*/ | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import BaseSchema from '@ioc:Adonis/Lucid/Schema' | ||
|
||
export default class Kicks extends BaseSchema { | ||
protected tableName = 'kicks' | ||
|
||
public async up () { | ||
this.schema.createTable(this.tableName, (table) => { | ||
table.increments('id') | ||
|
||
table.integer('from_user_id').unsigned().notNullable() | ||
.references('id').inTable('users').onDelete('CASCADE') | ||
table.integer('to_user_id').unsigned().notNullable() | ||
.references('id').inTable('users').onDelete('CASCADE') | ||
table.integer('channel_id').unsigned().notNullable() | ||
.references('id').inTable('channels').onDelete('CASCADE') | ||
|
||
/** | ||
* Uses timestamptz for PostgreSQL and DATETIME2 for MSSQL | ||
*/ | ||
table.timestamp('created_at', { useTz: true }) | ||
table.timestamp('updated_at', { useTz: true }) | ||
}) | ||
} | ||
|
||
public async down () { | ||
this.schema.dropTable(this.tableName) | ||
} | ||
} |