Prevent sequelize to drop database in node.js app
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
First of all, I am using node.js with sequelize ORM and Postgres SQL.
I have 2 simple questions:
Every time I rerun my node application sequelize is dropping and creating all tables in database. How to prevent it from doing that (I don't want my records in database to be deleted)? I have tried to set my NODE_ENV to test but it didn't help.
How does sequelize migration knows where it stopped (which migration have executed and which not).
When I was using database migration in Grails framework, for example, it automatically created a table in the database where it kept all migration timestamps that executed before and when I rerun my application it looks at that table and knows which migrations are already done and which are not.
I don't see any table when using node/sequelize, so how it works? :)
Thanks,
Ivan
node.js postgresql sequelize.js
add a comment |
First of all, I am using node.js with sequelize ORM and Postgres SQL.
I have 2 simple questions:
Every time I rerun my node application sequelize is dropping and creating all tables in database. How to prevent it from doing that (I don't want my records in database to be deleted)? I have tried to set my NODE_ENV to test but it didn't help.
How does sequelize migration knows where it stopped (which migration have executed and which not).
When I was using database migration in Grails framework, for example, it automatically created a table in the database where it kept all migration timestamps that executed before and when I rerun my application it looks at that table and knows which migrations are already done and which are not.
I don't see any table when using node/sequelize, so how it works? :)
Thanks,
Ivan
node.js postgresql sequelize.js
Can you include some code? I'm using sequelize with postgresql and haven't had that problem.
– MikeSmithDev
Jan 2 '14 at 14:08
I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example)
– ivan_zd
Jan 2 '14 at 15:22
1
I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :)
– ivan_zd
Jan 2 '14 at 17:34
add a comment |
First of all, I am using node.js with sequelize ORM and Postgres SQL.
I have 2 simple questions:
Every time I rerun my node application sequelize is dropping and creating all tables in database. How to prevent it from doing that (I don't want my records in database to be deleted)? I have tried to set my NODE_ENV to test but it didn't help.
How does sequelize migration knows where it stopped (which migration have executed and which not).
When I was using database migration in Grails framework, for example, it automatically created a table in the database where it kept all migration timestamps that executed before and when I rerun my application it looks at that table and knows which migrations are already done and which are not.
I don't see any table when using node/sequelize, so how it works? :)
Thanks,
Ivan
node.js postgresql sequelize.js
First of all, I am using node.js with sequelize ORM and Postgres SQL.
I have 2 simple questions:
Every time I rerun my node application sequelize is dropping and creating all tables in database. How to prevent it from doing that (I don't want my records in database to be deleted)? I have tried to set my NODE_ENV to test but it didn't help.
How does sequelize migration knows where it stopped (which migration have executed and which not).
When I was using database migration in Grails framework, for example, it automatically created a table in the database where it kept all migration timestamps that executed before and when I rerun my application it looks at that table and knows which migrations are already done and which are not.
I don't see any table when using node/sequelize, so how it works? :)
Thanks,
Ivan
node.js postgresql sequelize.js
node.js postgresql sequelize.js
edited Mar 28 at 21:49
Fozoro
1,8712927
1,8712927
asked Jan 2 '14 at 11:46
ivan_zdivan_zd
1,25832036
1,25832036
Can you include some code? I'm using sequelize with postgresql and haven't had that problem.
– MikeSmithDev
Jan 2 '14 at 14:08
I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example)
– ivan_zd
Jan 2 '14 at 15:22
1
I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :)
– ivan_zd
Jan 2 '14 at 17:34
add a comment |
Can you include some code? I'm using sequelize with postgresql and haven't had that problem.
– MikeSmithDev
Jan 2 '14 at 14:08
I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example)
– ivan_zd
Jan 2 '14 at 15:22
1
I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :)
– ivan_zd
Jan 2 '14 at 17:34
Can you include some code? I'm using sequelize with postgresql and haven't had that problem.
– MikeSmithDev
Jan 2 '14 at 14:08
Can you include some code? I'm using sequelize with postgresql and haven't had that problem.
– MikeSmithDev
Jan 2 '14 at 14:08
I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example)
– ivan_zd
Jan 2 '14 at 15:22
I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example)
– ivan_zd
Jan 2 '14 at 15:22
1
1
I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :)
– ivan_zd
Jan 2 '14 at 17:34
I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :)
– ivan_zd
Jan 2 '14 at 17:34
add a comment |
1 Answer
1
active
oldest
votes
As you already figured out, the tables are being dropped because you are doing
sequelize.sync({ force: true })
The force true part being the culprit
To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20882230%2fprevent-sequelize-to-drop-database-in-node-js-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As you already figured out, the tables are being dropped because you are doing
sequelize.sync({ force: true })
The force true part being the culprit
To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta
add a comment |
As you already figured out, the tables are being dropped because you are doing
sequelize.sync({ force: true })
The force true part being the culprit
To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta
add a comment |
As you already figured out, the tables are being dropped because you are doing
sequelize.sync({ force: true })
The force true part being the culprit
To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta
As you already figured out, the tables are being dropped because you are doing
sequelize.sync({ force: true })
The force true part being the culprit
To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta
answered Jan 3 '14 at 10:33
Jan Aagaard MeierJan Aagaard Meier
16.3k36254
16.3k36254
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20882230%2fprevent-sequelize-to-drop-database-in-node-js-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you include some code? I'm using sequelize with postgresql and haven't had that problem.
– MikeSmithDev
Jan 2 '14 at 14:08
I copied they express example on sequelize.js web page and only put postgre database instead of mysql (like they did in example) github.com/sequelize/sequelize-expressjs-example (link of their example)
– ivan_zd
Jan 2 '14 at 15:22
1
I figured out. They put sync: { force: true } in some part of code in app.js and that override my sync (false) that I defined when connecting to database...now second question is all that bothers me :)
– ivan_zd
Jan 2 '14 at 17:34