Comments (2)
"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.
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)
- There is an Internal Server Error while uploading an image in strapi on localhost HOT 1
- Upgrade Frontend to Tailwind v3. HOT 1
- Page not Found error in client while run on localhost HOT 3
- Preview Mode provide a example url HOT 2
- seed.js: ADMIN_JWT_SECRET appended to existing line and yarn seed not copying images HOT 2
- Global > Footer includes Shared > FooterColumns but is not selectable HOT 1
- Start foodadvisor strapi project with "npm run develop" HOT 1
- Update https://foodadvisor.strapi.io/ to the new frontend HOT 1
- PageNotFound error on client HOT 1
- error: select "t0".* from "scheduler_scheduler" as "t0" where ("t0"."uid" = $1 and "t0"."content_id" = $2) - invalid input syntax for type bigint: "null"
- Node.js 18 - Error fetching localhost HOT 1
- Size of the repo is enormous HOT 3
- NodeJS 16 is EOL HOT 1
- The engine "node" is incompatible with this module. Expected version ">=14.x.x <=16.x.x". Got "18.18.2" HOT 1
- Remove populate deep plugin HOT 4
- How to access the strapi public url after deployment
- Where is the v2 branch? HOT 1
- ENAMETOOLONG when trying to seed project HOT 3
- Update Readme to include requirement that this project currently works with Node version 16.x.x HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from foodadvisor.