mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-03 21:25:13 +00:00
Prevent sqlite db to overwrite while installing my ElectronNet application #852
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @krishrana17 on GitHub (Mar 19, 2023).
I am developing an Electron.NET application using .NET Core 6 and I want to prevent my SQLite database file from being overwritten during the installation process if it already exists. I have added the necessary code to my manually created 'main.js' file to check for the existence of the file and copy it only if it doesn't exist. However, when I build the package using 'electronize build /target win', the code in my 'main.js' file is not reflected in the built package. Is this a bug or am I missing something?
`const fs = require('fs');
const path = require('path');
const { app } = require('electron');
// Get the installation directory
const appPath = app.getPath('exe');
const installDir = path.dirname(appPath);
// Check if the database file already exists
const dbFile = path.join(installDir, 'mydb.sqlite');
if (!fs.existsSync(dbFile)) {
const resourcePath = path.join(__dirname, 'mydb.sqlite');
fs.copyFileSync(resourcePath, dbFile);
}`
@FlorianRappl commented on GitHub (Mar 19, 2023):
Can you create a full MWE e.g., as a GitHub repository? It would help to see what you actually do and if this is indeed a bug.
@krishrana17 commented on GitHub (Mar 20, 2023):
Let me try to give you the more detail. There is only one page which simply displays the list of users (dummy users) from "Users" table from Sqlite db.
To create table in Sqlite db, i am using "FluentMigrator" and have configured it like this in my program.cs file.
`
builder.Services.AddFluentMigratorCore()
`
and in the appsettings.json file, I have defined the connection string like this -
"ConnectionStrings": { "UserConnectionString": "Data Source=mydb.sqlite" },So when you run the application, "FluentMigrator" will create the table schema and insert the dummy data using following code.
`[Migration(20230318)]
public class Migrate_CreateUsersTable : Migration
{
}`
Now in my Visual Studio solution, I have mark this sqlite db file as "Embed Resource" as shown in below image.
Basically what I am trying to do is - when I will first time install this electron app in client machine at that time I want electron setup to copy sqlite db file in client machine. Now after few days, let say If I have released some new feature then in the second installation I don't want electron setup will copy that sqlite db file because it was already there in the client machine. And I don't want electron setup will replace that file on subsequent installation. Can anybody helped here where to look for that @GregorBiswanger? Write now I am trying to control that by writing below code in "main.js" file. But that's approach not working.
`const fs = require('fs');
const path = require('path');
const { app } = require('electron');
// Get the installation directory
const appPath = app.getPath('exe');
const installDir = path.dirname(appPath);
// Check if the database file already exists
const dbFile = path.join(installDir, 'mydb.sqlite');
if (!fs.existsSync(dbFile)) {
const resourcePath = path.join(__dirname, 'mydb.sqlite');
fs.copyFileSync(resourcePath, dbFile);
}`
@FlorianRappl commented on GitHub (Mar 20, 2023):
Well, again, what I'm asking is a simple reproducible with a GitHub repository. If I understood the OP the problem is not at all related to sqlite (not sure why this was brought up then), but rather the usage of your main.js.
So again, just provide a MWE showing your exact problem - once we have a reproducible we can take care of it.
@Elanchezhiyan-P commented on GitHub (Jun 24, 2024):
@krishrana17 , How do you package the electron application? When you use Visual studio project installer, it has the capability to create new or replace option when installed freshly or updating it to the existing application.
@FlorianRappl commented on GitHub (Nov 10, 2025):
Stale issue that does not seem to originate from Electron.NET.