在node.js中测试后清理数据库 [英] Cleaning database after tests in node.js

查看:98
本文介绍了在node.js中测试后清理数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次后如何清理数据库?

How I can clean database after each it?

在Rails中,我使用 https://github.com/bmabey/database_cleaner ,但我确实做到了找不到与node.js类似的东西

In rails I use https://github.com/bmabey/database_cleaner, but I did't find something similar for node.js

node.js(v0.10.26),PostgreSQL(9.3.3),mocha,restify和knex.

node.js (v0.10.26), PostgreSQL (9.3.3), mocha, restify and knex.

推荐答案

我发现在测试之间清理数据库的简单方法是

The easy way I have found to clean the database between test is to

DROP SCHEMA public CASCADE;
CREATE SCHEMA public AUTHORIZATION my_test_user;

一旦公共模式属于测试用户,他就可以在需要时删除并重新创建模式.请注意,删除数据库公共模式中的所有内容.

Once the public schema belongs to the test user, he is able to drop and re-create the schema when needed. Be aware that drop everything that lies in your database's public schema.

这篇关于在node.js中测试后清理数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆