Coder Social home page Coder Social logo

Comments (2)

alisharafian avatar alisharafian commented on June 23, 2024

"Thanks to my friend Subhan Behjati for solving this problem"
First, extract the information from the sqlite database with the "datagrip" program and convert it to "mysql". And then create a new folder in the "api" folder and I named it data and put the database converted to "mysql" in that folder and create a new "seed" file that contains the information about the "mysql" database.
for example new seed file : const fs = require('fs');
const path = require('path');
const knex = require('knex');
const fse = require('fs-extra');

// Define the path to your SQL file
const sqlFilePath = path.join(__dirname, '../data/strapi_food.sql');

// Read the SQL file
const sqlQueries = fs.readFileSync(sqlFilePath, 'utf-8');

const uploadDataPath = path.join(path.resolve('data'), 'uploads');
const uploadPath = path.join(path.resolve('public'), 'uploads');

const tmpPath = path.resolve('.tmp');

// Configure the database connection
const db = knex({
client: 'mysql',
connection: {
host: 'localhost',
user: 'root',
password: '',
database: 'strapi_db',
},
});

async function updateUid() {
const filePath = ./package.json;

try {
if (fse.existsSync(filePath)) {
const rawFile = fse.readFileSync(filePath);
const packageJSON = JSON.parse(rawFile);

  if (packageJSON.strapi.uuid.includes('FOODADVISOR')) return null;

  packageJSON.strapi.uuid =
    `FOODADVISOR-${
      process.env.GITPOD_WORKSPACE_URL ? 'GITPOD-' : 'LOCAL-'
    }` + uuid();

  const data = JSON.stringify(packageJSON, null, 2);
  fse.writeFileSync(filePath, data);
}

} catch (e) {
console.error(e);
}
}

async function dumpMySQL() {
// Split the queries using the delimiter (assuming each query ends with ';')
const queries = sqlQueries.split(';');

// Remove any empty queries
const validQueries = queries.filter((query) => query.trim() !== '');

// Execute each query
for (const query of validQueries) {
await db.raw(query);
console.log(Query executed: ${query});
}
console.log('Seed completed successfully.');
// Disconnect from the database
await db.destroy();
}

// Function to execute SQL queries
async function sobhanCustom_executeQueries() {
try {
await updateUid();
} catch (error) {
console.log(error);
}

try {
await fse.emptyDir(tmpPath);
} catch (err) {
console.log(Failed to remove ${tmpPath});
}

try {
await dumpMySQL();
} catch (error) {
console.error('Error executing seed:', error);
}

try {
await fse.emptyDir(uploadPath);
} catch (err) {
console.log(Failed to remove ${uploadPath});
}

try {
await fse.copy(uploadDataPath, uploadPath, { overwrite: true });
} catch (err) {
console.log(Failed to move ${uploadDataPath} to ${uploadPath});
}

}

// Run the seed
sobhanCustom_executeQueries();

from foodadvisor.

alisharafian avatar alisharafian commented on June 23, 2024

and you need change database.js like this :

module.exports = ({ env }) => {
const client = env('DATABASE_CLIENT', 'mysql');

const connections = {
mysql: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 3306),
database: env('DATABASE_NAME', 'strapi_db'),
user: env('DATABASE_USERNAME', 'root'),
password: env('DATABASE_PASSWORD', ''),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
true
),
},
}

from foodadvisor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.