mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	VACUUM for migration
This commit is contained in:
		
							parent
							
								
									61ddd8afc6
								
							
						
					
					
						commit
						60d000b9cb
					
				@ -1,2 +1,2 @@
 | 
				
			|||||||
UPDATE options SET name = 'eraseEntitiesAfterTimeInSeconds' WHERE name = 'eraseNotesAfterTimeInSeconds';
 | 
					UPDATE options SET name = 'eraseEntitiesAfterTimeInSeconds' WHERE name = 'eraseNotesAfterTimeInSeconds';
 | 
				
			||||||
UPDATE entity_changes SET entityName = 'eraseEntitiesAfterTimeInSeconds' WHERE entityName = 'eraseNotesAfterTimeInSeconds';
 | 
					UPDATE entity_changes SET entityId = 'eraseEntitiesAfterTimeInSeconds' WHERE entityName = 'options' AND entityId = 'eraseNotesAfterTimeInSeconds';
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								db/migrations/0179__VACUUM.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								db/migrations/0179__VACUUM.sql
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					VACUUM
 | 
				
			||||||
@ -4,7 +4,7 @@ const build = require('./build');
 | 
				
			|||||||
const packageJson = require('../../package');
 | 
					const packageJson = require('../../package');
 | 
				
			||||||
const {TRILIUM_DATA_DIR} = require('./data_dir');
 | 
					const {TRILIUM_DATA_DIR} = require('./data_dir');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const APP_DB_VERSION = 178;
 | 
					const APP_DB_VERSION = 179;
 | 
				
			||||||
const SYNC_VERSION = 19;
 | 
					const SYNC_VERSION = 19;
 | 
				
			||||||
const CLIPPER_PROTOCOL_VERSION = "1.0";
 | 
					const CLIPPER_PROTOCOL_VERSION = "1.0";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,28 @@ const utils = require('./utils');
 | 
				
			|||||||
const resourceDir = require('./resource_dir');
 | 
					const resourceDir = require('./resource_dir');
 | 
				
			||||||
const appInfo = require('./app_info');
 | 
					const appInfo = require('./app_info');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function executeMigration(mig) {
 | 
				
			||||||
 | 
					    sql.transactional(() => {
 | 
				
			||||||
 | 
					        if (mig.type === 'sql') {
 | 
				
			||||||
 | 
					            const migrationSql = fs.readFileSync(resourceDir.MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            console.log("Migration with SQL script: " + migrationSql);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            sql.executeScript(migrationSql);
 | 
				
			||||||
 | 
					        } else if (mig.type === 'js') {
 | 
				
			||||||
 | 
					            console.log("Migration with JS module");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const migrationModule = require(resourceDir.MIGRATIONS_DIR + "/" + mig.file);
 | 
				
			||||||
 | 
					            migrationModule();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            throw new Error("Unknown migration type " + mig.type);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // not using repository because of changed utcDateModified column in migration 129
 | 
				
			||||||
 | 
					        sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function migrate() {
 | 
					async function migrate() {
 | 
				
			||||||
    const migrations = [];
 | 
					    const migrations = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,27 +65,13 @@ async function migrate() {
 | 
				
			|||||||
        try {
 | 
					        try {
 | 
				
			||||||
            log.info("Attempting migration to version " + mig.dbVersion);
 | 
					            log.info("Attempting migration to version " + mig.dbVersion);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            sql.transactional(() => {
 | 
					            if (mig.name === 'VACUUM') {
 | 
				
			||||||
                if (mig.type === 'sql') {
 | 
					                // special case since VACUUM can't be executed in a transaction
 | 
				
			||||||
                    const migrationSql = fs.readFileSync(resourceDir.MIGRATIONS_DIR + "/" + mig.file).toString('utf8');
 | 
					                sql.execute('VACUUM');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
                    console.log("Migration with SQL script: " + migrationSql);
 | 
					            else {
 | 
				
			||||||
 | 
					                executeMigration(mig);
 | 
				
			||||||
                    sql.executeScript(migrationSql);
 | 
					            }
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else if (mig.type === 'js') {
 | 
					 | 
				
			||||||
                    console.log("Migration with JS module");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    const migrationModule = require(resourceDir.MIGRATIONS_DIR + "/" + mig.file);
 | 
					 | 
				
			||||||
                    migrationModule();
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else {
 | 
					 | 
				
			||||||
                    throw new Error("Unknown migration type " + mig.type);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // not using repository because of changed utcDateModified column in migration 129
 | 
					 | 
				
			||||||
                sql.execute(`UPDATE options SET value = ? WHERE name = ?`, [mig.dbVersion.toString(), "dbVersion"]);
 | 
					 | 
				
			||||||
            });
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            log.info("Migration to version " + mig.dbVersion + " has been successful.");
 | 
					            log.info("Migration to version " + mig.dbVersion + " has been successful.");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user