Hi, what it's the most simple way to clear local d...
# prisma-whats-new
f
Hi, what it's the most simple way to clear local database? (graphcool on local docker)
s
@fabien0102 You can access the underlying mysql database .. https://www.graph.cool/docs/reference/deployment/database-access-eif6eing5o
f
Fair enough, it was my first idea šŸ˜‰
a
graphcool local stop
followed by
docker volume prune
will completely reset your local environment
f
Nice! I prefer this solution šŸ™‚
Thx šŸ™‚
šŸ‘šŸ» 1
Now I can try safely my migration script šŸ˜ˆ
s
Not a docker expert.. but what I do is connect to the container on on port 3306 and delete all tables I care about for more rapid experimentation.. but @agarthaā€™s solution is probably cleaner
a
To just clear data for a single service, yours is probably easier.
f
@steve if you have a sql command to erase all the tables in one command, I take it (it should be quicker to reset)
a
I try to stay away from direct database manipulation. For one, you won't clear the functions container.
It's very easy to get into an inconsistent state. That's why I don't take the risk, because before you know it, you'll be spending hours debugging šŸ˜„
f
@agartha It was my thought, it's why I ask in this channel ^^
šŸ‘šŸ» 1
s
@agartha is right.. learned this the hard way. But when i'm just trying to figure something out and need a tight feedback loop I clear the tables I know about by name as they are the same name as your types
a
I use different local clusters for different services, so I can always safely use my method without destroying other locally deployed services. It's quite an overhead though, so it's not ideal either...
f
But maybe it exists a command to reset a docker container?
(I'm quite a noob in docker)
s
The
prune
command above will do that
a
@steve you are right, when you didn't make any changes to your service or schema and just want to reset the data, your method is perfectly safe.
f
Perfect, now I know how to reset all, I can try all your methods šŸ˜‰
s
@fabien0102 here is a quick script i threw together.. you will need to pass it the tables name you want to delete and the project id (you'll need to modify it to fit your needs) ..
Copy code
import mysql from 'mysql';
import projectId from '../tests/utils/projectId';

const createDbConnection = projectId => mysql.createConnection(
    {
        host     : 'localhost',
        port     :  3306,
        user     : 'root',
        password : 'graphcool',
        database : projectId
    }
);

const clearTables = (connection, tables) => {
    const query = (query) => new Promise(
        (resolve, reject) => {
            connection.query(query, (err, results) => (
                ((err && reject(err) && false) ||
                resolve(results))
            ))
        }
    )
    return Promise.all(tables.map(t => query(`delete from ${t};`)));  
};

export default (tables) => {
    const conn = createDbConnection(projectId());
    tables = [].concat(tables);
    conn.connect();
    return clearTables(conn, tables).then(()=>new Promise((res)=> conn.end(res)))
};
But you will also need to expose port 3306 on the container (port mapping is not setup on the mysql service currently)
Anyway, hope that helps a bit.
Caveat emptor though šŸ˜‰
f
It can be useful to add the reset snippet to the doc btw
always good to have, so you can do any experimentation safely XD
A nice to have for me will be
gc local reset
(with a confirmation message of course)
But it's totally fine for instant, thx for your support šŸ™‚
a
šŸ‘Œ 1
šŸ‘ 1
f
data import šŸ˜®
Niceeeeeeeee
BTW, all the script I seen for instant for data import deal with only one collection, do you plan something for relation (nestead json)?
a
f
Nice, I really need to read all this issues, many cool stuff on it šŸ™‚
a
Especially everything marked as 1.0. Everyone's feedback is valuable
f
Noted šŸ˜‰
n
https://github.com/graphcool/framework/pull/1318 is a great entry point into what's going on currently šŸ™‚