소스 검색

dev: add puter-linux app to db migrations

KernelDeimos 8 달 전
부모
커밋
25817bf6a2

+ 20 - 15
src/backend/src/services/database/SqliteDatabaseAccessService.js

@@ -44,21 +44,6 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
 
         this.db = new Database(this.config.path);
 
-        // Database upgrade logic
-        const HIGHEST_VERSION = 24;
-        const TARGET_VERSION = (() => {
-            const args = Context.get('args');
-            if ( args['database-target-version'] ) {
-                return parseInt(args['database-target-version']);
-            }
-            return HIGHEST_VERSION;
-        })();
-
-        const [{ user_version }] = do_setup
-            ? [{ user_version: -1 }]
-            : await this._read('PRAGMA user_version');
-        this.log.info('database version: ' + user_version);
-
         const upgrade_files = [];
 
         const available_migrations = [
@@ -138,8 +123,28 @@ class SqliteDatabaseAccessService extends BaseDatabaseAccessService {
             [23, [
                 '0026_user-groups.dbmig.js',
             ]],
+            [24, [
+                '0027_emulator-app.dbmig.js',
+            ]],
         ];
 
+        // Database upgrade logic
+        const HIGHEST_VERSION =
+            available_migrations[available_migrations.length - 1][0] + 1;
+        const TARGET_VERSION = (() => {
+            const args = Context.get('args');
+            if ( args['database-target-version'] ) {
+                return parseInt(args['database-target-version']);
+            }
+            return HIGHEST_VERSION;
+        })();
+
+        const [{ user_version }] = do_setup
+            ? [{ user_version: -1 }]
+            : await this._read('PRAGMA user_version');
+        this.log.info('database version: ' + user_version);
+
+
         for ( const [v_lt_or_eq, files] of available_migrations ) {
             if ( v_lt_or_eq + 1 >= TARGET_VERSION && TARGET_VERSION !== HIGHEST_VERSION ) {
                 this.log.noticeme(`Early exit: target version set to ${TARGET_VERSION}`);

+ 23 - 0
src/backend/src/services/database/sqlite_setup/0027_emulator-app.dbmig.js

@@ -0,0 +1,23 @@
+const insert = async (tbl, subject) => {
+    const keys = Object.keys(subject);
+
+    await write(
+        'INSERT INTO `'+ tbl +'` ' +
+        '(' + keys.map(key => key).join(', ') + ') ' +
+        'VALUES (' + keys.map(() => '?').join(', ') + ')',
+        keys.map(key => subject[key])
+    );
+}
+
+await insert('apps', {
+    uid: 'app-fbbdb72b-ad08-4cb4-86a1-de0f27cf2e1e',
+    owner_user_id: 1,
+    name: 'puter-linux',
+    index_url: 'https://builtins.namespaces.puter.com/emulator',
+    title: 'Puter Linux',
+    description: 'Linux emulator for Puter',
+    approved_for_listing: 1,
+    approved_for_opening_items: 1,
+    approved_for_incentive_program: 0,
+    timestamp: '2020-01-01 00:00:00',
+});

+ 1 - 1
src/gui/src/services/ExecService.js

@@ -100,7 +100,7 @@ export class ExecService extends Service {
         if ( caller_process.name !== 'phoenix' ) {
             throw new Error('Connection not allowed.');
         }
-        if ( app_name !== 'test-emu' ) {
+        if ( app_name !== 'puter-linux' ) {
             throw new Error('Connection not allowed.');
         }
 

+ 1 - 1
src/gui/src/services/ProcessService.js

@@ -23,7 +23,7 @@ const NULL_UUID = '00000000-0000-0000-0000-000000000000';
 
 export class ProcessService extends Service {
     static INITRC = [
-        'test-emu'
+        'puter-linux'
     ];
 
     async _init () {

+ 1 - 1
src/phoenix/src/puter-shell/providers/EmuCommandProvider.js

@@ -8,7 +8,7 @@ export class EmuCommandProvider {
         'emu-sort': '/usr/bin/sort',
     };
 
-    static EMU_APP_NAME = 'test-emu';
+    static EMU_APP_NAME = 'puter-linux';
 
     constructor () {
         this.available = this.constructor.AVAILABLE;