This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: user associated project * fix: add histoy creatBy * fix: import env fail * fix: add script for migration
- Loading branch information
Showing
23 changed files
with
338 additions
and
82 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 |
---|---|---|
|
@@ -38,4 +38,5 @@ lerna-debug.log* | |
/sample | ||
|
||
# env | ||
.env.local | ||
.env.prodction |
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,24 @@ | ||
export default class Page<T> { | ||
records: Array<T>; | ||
|
||
pageNumber: number; | ||
|
||
pageSize: number; | ||
|
||
pageCount: number; | ||
|
||
total: number; | ||
|
||
constructor( | ||
pageNumber: number, | ||
pageSize: number, | ||
total: number, | ||
records: Array<T>, | ||
) { | ||
this.pageNumber = pageNumber; | ||
this.pageSize = pageSize; | ||
this.total = total; | ||
this.records = records; | ||
this.pageCount = Math.ceil(total / pageSize); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,37 +1,48 @@ | ||
import { DataSourceOptions } from 'typeorm'; | ||
import { DataSource, DataSourceOptions } from 'typeorm'; | ||
|
||
export const getConfiguration = () => ({ | ||
// jwt sign secret | ||
jwt: { | ||
secret: process.env.JWT_SECRET || '123456', | ||
}, | ||
// typeorm config | ||
database: { | ||
type: 'mysql', | ||
host: process.env.MYSQL_HOST, | ||
port: Number.parseInt(process.env.MYSQL_PORT, 10), | ||
username: process.env.MYSQL_USERNAME, | ||
password: process.env.MYSQL_ROOT_PASSWORD, | ||
database: process.env.MYSQL_DATABASE, | ||
entities: [__dirname + '/../**/entities/*.entity.{ts,js}'], | ||
autoLoadEntities: true, | ||
synchronize: false, | ||
logging: ['error'], | ||
timezone: '+08:00', // 东八区 | ||
migrations: ['dist/src/migrations/**/*.js'], | ||
migrationsRun: true, | ||
cli: { | ||
migrationsDir: 'src/migrations', | ||
export let appDataSource: DataSource; | ||
|
||
export const getAppDataSource = (): DataSource => { | ||
return appDataSource; | ||
}; | ||
|
||
export const getConfiguration = () => { | ||
const config = { | ||
// jwt sign secret | ||
jwt: { | ||
secret: process.env.JWT_SECRET || '123456', | ||
}, | ||
// typeorm config | ||
database: { | ||
type: 'mysql', | ||
host: process.env.MYSQL_HOST, | ||
port: Number.parseInt(process.env.MYSQL_PORT, 10), | ||
username: process.env.MYSQL_USERNAME, | ||
password: process.env.MYSQL_ROOT_PASSWORD, | ||
database: process.env.MYSQL_DATABASE, | ||
entities: [__dirname + '/../**/entities/*.entity.{ts,js}'], | ||
autoLoadEntities: true, | ||
synchronize: false, | ||
logging: ['error'], | ||
timezone: '+08:00', // 东八区 | ||
migrations: ['dist/src/migrations/**/*.js'], | ||
migrationsRun: true, | ||
cli: { | ||
migrationsDir: 'src/migrations', | ||
}, | ||
} as DataSourceOptions, | ||
// swagger | ||
swagger: { | ||
enable: process.env.SWAGGER_ENABLE === 'true', | ||
path: process.env.SWAGGER_PATH, | ||
title: process.env.SWAGGER_TITLE, | ||
desc: process.env.SWAGGER_DESC, | ||
version: process.env.SWAGGER_VERSION, | ||
}, | ||
} as DataSourceOptions, | ||
// swagger | ||
swagger: { | ||
enable: process.env.SWAGGER_ENABLE === 'true', | ||
path: process.env.SWAGGER_PATH, | ||
title: process.env.SWAGGER_TITLE, | ||
desc: process.env.SWAGGER_DESC, | ||
version: process.env.SWAGGER_VERSION, | ||
}, | ||
}); | ||
}; | ||
appDataSource = new DataSource(config.database); | ||
// appDataSource.initialize(); | ||
return config; | ||
}; | ||
|
||
export default getConfiguration(); |
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
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,58 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class updateTable1821666095643523 implements MigrationInterface { | ||
name = 'updateTable1821666095643523'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE \`project_users_user\` (\`projectUuid\` int NOT NULL, \`userId\` int NOT NULL, INDEX \`IDX_6a2f9d94e82e85ba623237023b\` (\`projectUuid\`), INDEX \`IDX_f8300efd87679e1e21532be980\` (\`userId\`), PRIMARY KEY (\`projectUuid\`, \`userId\`)) ENGINE=InnoDB`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`api_test_history\` ADD \`createBy\` int NOT NULL`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`api_test_history\` ADD \`updateBy\` int NOT NULL`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`project_users_user\` ADD CONSTRAINT \`FK_6a2f9d94e82e85ba623237023bd\` FOREIGN KEY (\`projectUuid\`) REFERENCES \`project\`(\`uuid\`) ON DELETE CASCADE ON UPDATE CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`project_users_user\` ADD CONSTRAINT \`FK_f8300efd87679e1e21532be9808\` FOREIGN KEY (\`userId\`) REFERENCES \`user\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
); | ||
|
||
const workspaces = await queryRunner.query( | ||
`SELECT * FROM workspace_users_user`, | ||
); | ||
|
||
const values = workspaces.map((item) => [item.workspaceId, item.userId]); | ||
console.log('values', values); | ||
if (values.length) { | ||
await queryRunner.query( | ||
`INSERT INTO project_users_user (projectUuid, userId) VALUES ?`, | ||
[values], | ||
); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE \`project_users_user\` DROP FOREIGN KEY \`FK_f8300efd87679e1e21532be9808\``, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`project_users_user\` DROP FOREIGN KEY \`FK_6a2f9d94e82e85ba623237023bd\``, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`api_test_history\` DROP COLUMN \`updateBy\``, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE \`api_test_history\` DROP COLUMN \`createBy\``, | ||
); | ||
await queryRunner.query( | ||
`DROP INDEX \`IDX_f8300efd87679e1e21532be980\` ON \`project_users_user\``, | ||
); | ||
await queryRunner.query( | ||
`DROP INDEX \`IDX_6a2f9d94e82e85ba623237023b\` ON \`project_users_user\``, | ||
); | ||
await queryRunner.query(`DROP TABLE \`project_users_user\``); | ||
} | ||
} |
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
Oops, something went wrong.