Add script to delete existing database (#44)
* Fix deployment creation time and hard coded title * Add delete database script * Use database file path from config file --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
0feeb9408d
commit
cfb4b4637c
@ -29,7 +29,8 @@
|
|||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format:check": "prettier --check .",
|
"format:check": "prettier --check .",
|
||||||
"db:load:fixtures": "DEBUG=snowball:* ts-node ./test/initialize-db.ts"
|
"db:load:fixtures": "DEBUG=snowball:* ts-node ./test/initialize-db.ts",
|
||||||
|
"db:delete": "DEBUG=snowball:* ts-node ./test/delete-db.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/fs-extra": "^11.0.4",
|
"@types/fs-extra": "^11.0.4",
|
||||||
|
21
packages/backend/test/delete-db.ts
Normal file
21
packages/backend/test/delete-db.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import * as fs from 'fs/promises';
|
||||||
|
import debug from 'debug';
|
||||||
|
|
||||||
|
import { getConfig } from '../src/utils';
|
||||||
|
import { Config } from '../src/config';
|
||||||
|
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
|
||||||
|
|
||||||
|
const log = debug('snowball:delete-database');
|
||||||
|
|
||||||
|
const deleteFile = async (filePath: string) => {
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
log(`File ${filePath} has been deleted.`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
const config = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
|
||||||
|
|
||||||
|
deleteFile(config.database.dbPath);
|
||||||
|
};
|
||||||
|
|
||||||
|
main().catch(err => log(err));
|
@ -11,11 +11,12 @@ import { EnvironmentVariable } from '../src/entity/EnvironmentVariable';
|
|||||||
import { Domain } from '../src/entity/Domain';
|
import { Domain } from '../src/entity/Domain';
|
||||||
import { ProjectMember } from '../src/entity/ProjectMember';
|
import { ProjectMember } from '../src/entity/ProjectMember';
|
||||||
import { Deployment } from '../src/entity/Deployment';
|
import { Deployment } from '../src/entity/Deployment';
|
||||||
|
import { getConfig } from '../src/utils';
|
||||||
|
import { Config } from '../src/config';
|
||||||
|
import { DEFAULT_CONFIG_FILE_PATH } from '../src/constants';
|
||||||
|
|
||||||
const log = debug('snowball:initialize-database');
|
const log = debug('snowball:initialize-database');
|
||||||
|
|
||||||
const DB_PATH = '../db/snowball';
|
|
||||||
|
|
||||||
const USER_DATA_PATH = './fixtures/users.json';
|
const USER_DATA_PATH = './fixtures/users.json';
|
||||||
const PROJECT_DATA_PATH = './fixtures/projects.json';
|
const PROJECT_DATA_PATH = './fixtures/projects.json';
|
||||||
const ORGANIZATION_DATA_PATH = './fixtures/organizations.json';
|
const ORGANIZATION_DATA_PATH = './fixtures/organizations.json';
|
||||||
@ -103,12 +104,13 @@ const checkFileExists = async (filePath: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const isDbPresent = await checkFileExists(path.resolve(__dirname, DB_PATH));
|
const config = await getConfig<Config>(DEFAULT_CONFIG_FILE_PATH);
|
||||||
|
const isDbPresent = await checkFileExists(config.database.dbPath);
|
||||||
|
|
||||||
if (!isDbPresent) {
|
if (!isDbPresent) {
|
||||||
const dataSource = new DataSource({
|
const dataSource = new DataSource({
|
||||||
type: 'better-sqlite3',
|
type: 'better-sqlite3',
|
||||||
database: 'db/snowball',
|
database: config.database.dbPath,
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
logging: true,
|
logging: true,
|
||||||
entities: [path.join(__dirname, '../src/entity/*')]
|
entities: [path.join(__dirname, '../src/entity/*')]
|
||||||
|
@ -86,7 +86,7 @@ const DeploymentDetailsCard = ({
|
|||||||
</div>
|
</div>
|
||||||
<div className="col-span-1 flex items-center">
|
<div className="col-span-1 flex items-center">
|
||||||
<Typography color="gray" className="grow">
|
<Typography color="gray" className="grow">
|
||||||
{relativeTimeMs(deployment.updatedAt)} ^ {deployment.author}
|
{relativeTimeMs(deployment.createdAt)} ^ {deployment.author}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Menu placement="bottom-start">
|
<Menu placement="bottom-start">
|
||||||
<MenuHandler>
|
<MenuHandler>
|
||||||
|
@ -28,7 +28,7 @@ const DeploymentDialogBodyCard = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Typography variant="small" className="text-black">
|
<Typography variant="small" className="text-black">
|
||||||
deployment title
|
{deployment.title}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography variant="small">
|
<Typography variant="small">
|
||||||
^ {deployment.branch} ^ {deployment.commit.hash}{' '}
|
^ {deployment.branch} ^ {deployment.commit.hash}{' '}
|
||||||
|
@ -46,6 +46,7 @@ export interface DeploymentDetails {
|
|||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
author: string;
|
author: string;
|
||||||
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user