How to remove Loopback model and references from database









up vote
1
down vote

favorite












I removed a model fully from my app: deleted the model.js and model.json from models, deleted a relation in another model, and erased it from model-config.json.



However, the table created for the model, and the column in the other model remain in the DB (in all environments). I tried auto-migrating, but they're still there.



Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?










share|improve this question

























    up vote
    1
    down vote

    favorite












    I removed a model fully from my app: deleted the model.js and model.json from models, deleted a relation in another model, and erased it from model-config.json.



    However, the table created for the model, and the column in the other model remain in the DB (in all environments). I tried auto-migrating, but they're still there.



    Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I removed a model fully from my app: deleted the model.js and model.json from models, deleted a relation in another model, and erased it from model-config.json.



      However, the table created for the model, and the column in the other model remain in the DB (in all environments). I tried auto-migrating, but they're still there.



      Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?










      share|improve this question













      I removed a model fully from my app: deleted the model.js and model.json from models, deleted a relation in another model, and erased it from model-config.json.



      However, the table created for the model, and the column in the other model remain in the DB (in all environments). I tried auto-migrating, but they're still there.



      Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?







      node.js loopbackjs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 29 at 21:41









      Traveling Tech Guy

      14.8k1481135




      14.8k1481135






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote














          Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?




          LoopBack is not able to detect which models were removed and drop the corresponding database tables.



          As you have discovered yourself, the solution is to go through the databases and drop the tables manually.



          BTW I don't recommend using LoopBack's autoupdate/automigrate functionality in production and highly advocate for maintaining a set of migration scripts as described e.g. in Martin Fowler's excellent article Evolutionary Database Design.



          LoopBack does not support migration scripts yet, but we are discussing how to implement them for LoopBack 4+, see https://github.com/strongloop/loopback-next/issues/487






          share|improve this answer



























            up vote
            0
            down vote













            Have you looked into using the built-in API?
            https://apidocs.strongloop.com/loopback/#app-deletemodelbyname






            share|improve this answer




















            • How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
              – Traveling Tech Guy
              Nov 3 at 23:05










            • Use it as you'd use datasource queries.
              – 666e736464617370
              Nov 4 at 14:22










            • But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
              – Traveling Tech Guy
              Nov 5 at 15:52










            • Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
              – 666e736464617370
              Nov 5 at 17:23


















            up vote
            0
            down vote



            accepted










            Ended up doing it manually - in 3 databases :(



            I'm closing the question, but willing to reopen if someone had a good answer.






            share|improve this answer




















              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
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53054245%2fhow-to-remove-loopback-model-and-references-from-database%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote














              Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?




              LoopBack is not able to detect which models were removed and drop the corresponding database tables.



              As you have discovered yourself, the solution is to go through the databases and drop the tables manually.



              BTW I don't recommend using LoopBack's autoupdate/automigrate functionality in production and highly advocate for maintaining a set of migration scripts as described e.g. in Martin Fowler's excellent article Evolutionary Database Design.



              LoopBack does not support migration scripts yet, but we are discussing how to implement them for LoopBack 4+, see https://github.com/strongloop/loopback-next/issues/487






              share|improve this answer
























                up vote
                1
                down vote














                Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?




                LoopBack is not able to detect which models were removed and drop the corresponding database tables.



                As you have discovered yourself, the solution is to go through the databases and drop the tables manually.



                BTW I don't recommend using LoopBack's autoupdate/automigrate functionality in production and highly advocate for maintaining a set of migration scripts as described e.g. in Martin Fowler's excellent article Evolutionary Database Design.



                LoopBack does not support migration scripts yet, but we are discussing how to implement them for LoopBack 4+, see https://github.com/strongloop/loopback-next/issues/487






                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote










                  Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?




                  LoopBack is not able to detect which models were removed and drop the corresponding database tables.



                  As you have discovered yourself, the solution is to go through the databases and drop the tables manually.



                  BTW I don't recommend using LoopBack's autoupdate/automigrate functionality in production and highly advocate for maintaining a set of migration scripts as described e.g. in Martin Fowler's excellent article Evolutionary Database Design.



                  LoopBack does not support migration scripts yet, but we are discussing how to implement them for LoopBack 4+, see https://github.com/strongloop/loopback-next/issues/487






                  share|improve this answer













                  Do I need to manually go through all databases and drop the table and column manually, or can I tell LB to pick up the changes on its own somehow?




                  LoopBack is not able to detect which models were removed and drop the corresponding database tables.



                  As you have discovered yourself, the solution is to go through the databases and drop the tables manually.



                  BTW I don't recommend using LoopBack's autoupdate/automigrate functionality in production and highly advocate for maintaining a set of migration scripts as described e.g. in Martin Fowler's excellent article Evolutionary Database Design.



                  LoopBack does not support migration scripts yet, but we are discussing how to implement them for LoopBack 4+, see https://github.com/strongloop/loopback-next/issues/487







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 11 at 15:06









                  Miroslav Bajtoš

                  6,7372665




                  6,7372665






















                      up vote
                      0
                      down vote













                      Have you looked into using the built-in API?
                      https://apidocs.strongloop.com/loopback/#app-deletemodelbyname






                      share|improve this answer




















                      • How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
                        – Traveling Tech Guy
                        Nov 3 at 23:05










                      • Use it as you'd use datasource queries.
                        – 666e736464617370
                        Nov 4 at 14:22










                      • But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
                        – Traveling Tech Guy
                        Nov 5 at 15:52










                      • Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
                        – 666e736464617370
                        Nov 5 at 17:23















                      up vote
                      0
                      down vote













                      Have you looked into using the built-in API?
                      https://apidocs.strongloop.com/loopback/#app-deletemodelbyname






                      share|improve this answer




















                      • How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
                        – Traveling Tech Guy
                        Nov 3 at 23:05










                      • Use it as you'd use datasource queries.
                        – 666e736464617370
                        Nov 4 at 14:22










                      • But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
                        – Traveling Tech Guy
                        Nov 5 at 15:52










                      • Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
                        – 666e736464617370
                        Nov 5 at 17:23













                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      Have you looked into using the built-in API?
                      https://apidocs.strongloop.com/loopback/#app-deletemodelbyname






                      share|improve this answer












                      Have you looked into using the built-in API?
                      https://apidocs.strongloop.com/loopback/#app-deletemodelbyname







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 2 at 22:15









                      666e736464617370

                      15516




                      15516











                      • How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
                        – Traveling Tech Guy
                        Nov 3 at 23:05










                      • Use it as you'd use datasource queries.
                        – 666e736464617370
                        Nov 4 at 14:22










                      • But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
                        – Traveling Tech Guy
                        Nov 5 at 15:52










                      • Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
                        – 666e736464617370
                        Nov 5 at 17:23

















                      • How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
                        – Traveling Tech Guy
                        Nov 3 at 23:05










                      • Use it as you'd use datasource queries.
                        – 666e736464617370
                        Nov 4 at 14:22










                      • But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
                        – Traveling Tech Guy
                        Nov 5 at 15:52










                      • Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
                        – 666e736464617370
                        Nov 5 at 17:23
















                      How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
                      – Traveling Tech Guy
                      Nov 3 at 23:05




                      How and where do I use it? Is it a one-time call, or do I need to keep it with my code?
                      – Traveling Tech Guy
                      Nov 3 at 23:05












                      Use it as you'd use datasource queries.
                      – 666e736464617370
                      Nov 4 at 14:22




                      Use it as you'd use datasource queries.
                      – 666e736464617370
                      Nov 4 at 14:22












                      But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
                      – Traveling Tech Guy
                      Nov 5 at 15:52




                      But I already removed the model from the code. Explicitly calling deleteModelByName on a non-existing model makes no code sense. Could you please elaborate on what the new code look like?
                      – Traveling Tech Guy
                      Nov 5 at 15:52












                      Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
                      – 666e736464617370
                      Nov 5 at 17:23





                      Apologies, apparently this method detaches the model but the data still persists. Check: github.com/strongloop/loopback/blob/…
                      – 666e736464617370
                      Nov 5 at 17:23











                      up vote
                      0
                      down vote



                      accepted










                      Ended up doing it manually - in 3 databases :(



                      I'm closing the question, but willing to reopen if someone had a good answer.






                      share|improve this answer
























                        up vote
                        0
                        down vote



                        accepted










                        Ended up doing it manually - in 3 databases :(



                        I'm closing the question, but willing to reopen if someone had a good answer.






                        share|improve this answer






















                          up vote
                          0
                          down vote



                          accepted







                          up vote
                          0
                          down vote



                          accepted






                          Ended up doing it manually - in 3 databases :(



                          I'm closing the question, but willing to reopen if someone had a good answer.






                          share|improve this answer












                          Ended up doing it manually - in 3 databases :(



                          I'm closing the question, but willing to reopen if someone had a good answer.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 12 at 1:55









                          Traveling Tech Guy

                          14.8k1481135




                          14.8k1481135



























                              draft saved

                              draft discarded
















































                              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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53054245%2fhow-to-remove-loopback-model-and-references-from-database%23new-answer', 'question_page');

                              );

                              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







                              這個網誌中的熱門文章

                              Barbados

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3