chore: update build process and database configuration.
- Updated configuration to exclude additional directories from electron-builder's build process. - Dropped the creation of the "files" table in the database schema. - Improved code organization and extracted the data path into a reusable function. - Updated database migration configuration to use a new migration manager. - Added database migration to create a table for file management. - A migration to remove the "files" table has been applied.
This commit is contained in:
parent
617af8b12a
commit
0ddef31ed8
@ -8,8 +8,10 @@ files:
|
|||||||
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
|
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}'
|
||||||
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
|
- '!{.env,.env.*,.npmrc,pnpm-lock.yaml}'
|
||||||
- '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
|
- '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
|
||||||
- '!src/*'
|
- '!src'
|
||||||
- '!local'
|
- '!local'
|
||||||
|
- '!scripts'
|
||||||
|
- '!resources'
|
||||||
asarUnpack:
|
asarUnpack:
|
||||||
- resources/**
|
- resources/**
|
||||||
win:
|
win:
|
||||||
|
|||||||
@ -1,11 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS files (
|
|
||||||
id TEXT PRIMARY KEY,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
file_name TEXT NOT NULL,
|
|
||||||
path TEXT NOT NULL,
|
|
||||||
size INTEGER NOT NULL,
|
|
||||||
ext TEXT NOT NULL,
|
|
||||||
type TEXT NOT NULL,
|
|
||||||
created_at TEXT NOT NULL,
|
|
||||||
count INTEGER DEFAULT 1
|
|
||||||
)
|
|
||||||
@ -4,12 +4,16 @@ import { app } from 'electron'
|
|||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
export const DATA_PATH = path.join(app.getPath('userData'), 'Data')
|
const getDataPath = () => {
|
||||||
|
const dataPath = path.join(app.getPath('userData'), 'Data')
|
||||||
if (!fs.existsSync(DATA_PATH)) {
|
if (!fs.existsSync(dataPath)) {
|
||||||
fs.mkdirSync(DATA_PATH, { recursive: true })
|
fs.mkdirSync(dataPath, { recursive: true })
|
||||||
|
}
|
||||||
|
return dataPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const DATA_PATH = getDataPath()
|
||||||
|
|
||||||
export const appConfig = new Store()
|
export const appConfig = new Store()
|
||||||
|
|
||||||
export const titleBarOverlayDark = {
|
export const titleBarOverlayDark = {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { Sequelize } from 'sequelize'
|
|||||||
import { SequelizeStorage, Umzug } from 'umzug'
|
import { SequelizeStorage, Umzug } from 'umzug'
|
||||||
|
|
||||||
import { DATA_PATH } from '../config'
|
import { DATA_PATH } from '../config'
|
||||||
|
import migrations from './migrations'
|
||||||
|
|
||||||
const sequelize = new Sequelize({
|
const sequelize = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
@ -12,7 +13,7 @@ const sequelize = new Sequelize({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const umzug = new Umzug({
|
const umzug = new Umzug({
|
||||||
migrations: { glob: 'src/main/database/migrations/*.js' },
|
migrations,
|
||||||
context: sequelize.getQueryInterface(),
|
context: sequelize.getQueryInterface(),
|
||||||
storage: new SequelizeStorage({ sequelize, modelName: 'Migration', tableName: 'migrations' }),
|
storage: new SequelizeStorage({ sequelize, modelName: 'Migration', tableName: 'migrations' }),
|
||||||
logger: Logger
|
logger: Logger
|
||||||
|
|||||||
50
src/main/database/migrations.ts
Normal file
50
src/main/database/migrations.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
import { DataTypes } from 'sequelize'
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
name: '20240912072241-create-files-table',
|
||||||
|
async up({ context }) {
|
||||||
|
await context.createTable('files', {
|
||||||
|
id: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
primaryKey: true
|
||||||
|
},
|
||||||
|
name: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
file_name: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
path: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
ext: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: DataTypes.TEXT,
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
|
count: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
defaultValue: 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async down({ context }) {
|
||||||
|
await context.dropTable('files')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -1,48 +0,0 @@
|
|||||||
const { Sequelize } = require('sequelize')
|
|
||||||
|
|
||||||
async function up({ context: queryInterface }) {
|
|
||||||
await queryInterface.createTable('files', {
|
|
||||||
id: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
name: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
file_name: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
path: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
size: {
|
|
||||||
type: Sequelize.INTEGER,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
ext: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
type: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
created_at: {
|
|
||||||
type: Sequelize.TEXT,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
count: {
|
|
||||||
type: Sequelize.INTEGER,
|
|
||||||
defaultValue: 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function down({ context: queryInterface }) {
|
|
||||||
await queryInterface.dropTable('files')
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { up, down }
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
|
import { FileMetadata, FileType } from '@types'
|
||||||
import { DataTypes, Model } from 'sequelize'
|
import { DataTypes, Model } from 'sequelize'
|
||||||
|
|
||||||
import { FileMetadata, FileType } from '../../../renderer/src/types'
|
|
||||||
import sequelize from '..'
|
import sequelize from '..'
|
||||||
|
|
||||||
class FileModel extends Model<FileMetadata> implements FileMetadata {
|
class FileModel extends Model<FileMetadata> implements FileMetadata {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user