Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. This code will self-destruct in...

This code will self-destruct in...

Scheduled Pinned Locked Moved The Lounge
databasequestion
43 Posts 27 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nish Nishant

    Isn't the standard pattern to add a nullable column, then once the data's all there, make it non-nullable?

    Nish Nishant Consultant Software Architect Ganymede Software Solutions LLC www.ganymedesoftwaresolutions.com

    C Offline
    C Offline
    Chris Maunder
    wrote on last edited by
    #4

    You've just sent every DBA in the room screaming and clawing at their eyeballs ;) The situation is that the new code expects a column; the old version doesn't. Usually you can just update the database without the old code caring, then update the code and the new code picks up the new column. What if you can't run the migration until after you deploy the code because part of the migration will screw up, right royally, the old code? (The specific situation I have is a field being renamed then a new field being added with the previous name. Bad naming choices years ago...)

    cheers Chris Maunder

    W J A 3 Replies Last reply
    0
    • C Chris Maunder

      I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

      cheers Chris Maunder

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #5

      Most code seems to self destruct as soon as users get their hands on it anyway, so ...

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • C Chris Maunder

        I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

        cheers Chris Maunder

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #6

        Isn't that just a simple case of the app checking for updates? I've got that pretty much standard in larger apps, compares date of itself (and dependencies) against the same file name(s) in a read-only deployment directory, if newer version fire off the [external to avoid file lock] updatater and exits (also passing command args to updater) updater does it's work and fires off the app again with the same args. simple, efficient, unattended.

        Installing Signature... Do not switch off your computer.

        C 1 Reply Last reply
        0
        • C Chris Maunder

          You've just sent every DBA in the room screaming and clawing at their eyeballs ;) The situation is that the new code expects a column; the old version doesn't. Usually you can just update the database without the old code caring, then update the code and the new code picks up the new column. What if you can't run the migration until after you deploy the code because part of the migration will screw up, right royally, the old code? (The specific situation I have is a field being renamed then a new field being added with the previous name. Bad naming choices years ago...)

          cheers Chris Maunder

          W Offline
          W Offline
          W Balboos GHB
          wrote on last edited by
          #7

          So you can't just test for the existence of the newly named old column by its new name and handle accordingly (and where necessary)? In code and queries. Seems a safe and simple-minded solution. Handles itself, and some day you just strip out the conditional (while doing some other upgrade?).

          Ravings en masse^

          "The difference between genius and stupidity is that genius has its limits." - Albert Einstein

          "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

          J 1 Reply Last reply
          0
          • C Chris Maunder

            I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

            cheers Chris Maunder

            N Offline
            N Offline
            Nagy Vilmos
            wrote on last edited by
            #8

            API versions?

            veni bibi saltavi

            1 Reply Last reply
            0
            • C Chris Maunder

              I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

              cheers Chris Maunder

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #9

              It might be a change to your current processes but one way is to use batch scripts to handle this sort of thing. This is how we make these changes where I work. All DDL and DML changes are scripted in files and these scripts are then run against the database on a weekly or twice weekly basis in the case of sprint releases. There will inevitably be a few minutes downtime while the DDL scripts run. This then keeps your maintenance scripts outside of the application and also enables you to keep track of changes made to the database outside of the application. ...or have I completely misunderstood you.

              “That which can be asserted without evidence, can be dismissed without evidence.”

              ― Christopher Hitchens

              C 1 Reply Last reply
              0
              • C Chris Maunder

                I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                cheers Chris Maunder

                abmvA Offline
                abmvA Offline
                abmv
                wrote on last edited by
                #10

                when u mean code you mean like c# or tsql... ? well if you have a ORM framework you just update the code and it updates the database and later you shut the update mechanism and your unit tests take care of the checking...

                Caveat Emptor. "Progress doesn't come from early risers – progress is made by lazy men looking for easier ways to do things." Lazarus Long

                We are in the beginning of a mass extinction. - Greta Thunberg

                1 Reply Last reply
                0
                • L Lost User

                  Isn't that just a simple case of the app checking for updates? I've got that pretty much standard in larger apps, compares date of itself (and dependencies) against the same file name(s) in a read-only deployment directory, if newer version fire off the [external to avoid file lock] updatater and exits (also passing command args to updater) updater does it's work and fires off the app again with the same args. simple, efficient, unattended.

                  Installing Signature... Do not switch off your computer.

                  C Offline
                  C Offline
                  Chris Maunder
                  wrote on last edited by
                  #11

                  An app rewriting itself is really the closest I could envision at the moment. An update is close, but it's a wholesale replacement, not a chameleon like morphing.

                  cheers Chris Maunder

                  H 1 Reply Last reply
                  0
                  • G GuyThiebaut

                    It might be a change to your current processes but one way is to use batch scripts to handle this sort of thing. This is how we make these changes where I work. All DDL and DML changes are scripted in files and these scripts are then run against the database on a weekly or twice weekly basis in the case of sprint releases. There will inevitably be a few minutes downtime while the DDL scripts run. This then keeps your maintenance scripts outside of the application and also enables you to keep track of changes made to the database outside of the application. ...or have I completely misunderstood you.

                    “That which can be asserted without evidence, can be dismissed without evidence.”

                    ― Christopher Hitchens

                    C Offline
                    C Offline
                    Chris Maunder
                    wrote on last edited by
                    #12

                    Our issue is merely a catalyst for what I was thinking about. There's tons of ways to change our process, but it's more about the concept of code actively changing itself: you write a small hack, and a week later that hack has gone. The code actively cleans up itself. Maybe the IDE is involved. Maybe it's the compiler. Just thinking.

                    cheers Chris Maunder

                    K 2 Replies Last reply
                    0
                    • C Chris Maunder

                      I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                      cheers Chris Maunder

                      K Offline
                      K Offline
                      kmoorevs
                      wrote on last edited by
                      #13

                      I've got (desktop lob) apps that have been in deployment for over 10 years. One of the first things an application does after connecting to the database is to check it's version against the database version. A special table is used to record schema changes, currently adding a simple tinyint (either exists or not, and if so completed successfully or not) descriptively named column for single or batch mod...if I had it to do over, I might rather use a row-based solution to record more details per database mod. (such as comments/notes, datetime applied, app version, or even an optional expiration date) Running an older app against a newer database simply nags for an application update and warns of the possible consequences of non-compliance. (only happens occasionally in multi-user scenarios) :) Edit: Nevermind...after reading more it seems like you're after AI! :laugh:

                      "Go forth into the source" - Neal Morse

                      J 1 Reply Last reply
                      0
                      • C Chris Maunder

                        You've just sent every DBA in the room screaming and clawing at their eyeballs ;) The situation is that the new code expects a column; the old version doesn't. Usually you can just update the database without the old code caring, then update the code and the new code picks up the new column. What if you can't run the migration until after you deploy the code because part of the migration will screw up, right royally, the old code? (The specific situation I have is a field being renamed then a new field being added with the previous name. Bad naming choices years ago...)

                        cheers Chris Maunder

                        J Offline
                        J Offline
                        Jeremy Falcon
                        wrote on last edited by
                        #14

                        I don't think you have a choice but to go down for maintenance man. Adding temp code just seems like a bad idea for production environments. It'll also clutter up the code base in source control. Is there any way you can do the rollout in chunks at least instead of all servers at once?

                        Jeremy Falcon

                        1 Reply Last reply
                        0
                        • K kmoorevs

                          I've got (desktop lob) apps that have been in deployment for over 10 years. One of the first things an application does after connecting to the database is to check it's version against the database version. A special table is used to record schema changes, currently adding a simple tinyint (either exists or not, and if so completed successfully or not) descriptively named column for single or batch mod...if I had it to do over, I might rather use a row-based solution to record more details per database mod. (such as comments/notes, datetime applied, app version, or even an optional expiration date) Running an older app against a newer database simply nags for an application update and warns of the possible consequences of non-compliance. (only happens occasionally in multi-user scenarios) :) Edit: Nevermind...after reading more it seems like you're after AI! :laugh:

                          "Go forth into the source" - Neal Morse

                          J Offline
                          J Offline
                          Jeremy Falcon
                          wrote on last edited by
                          #15

                          That's a catchy idea. Although, he'd still run into the scenario of a newer app running against an older DB. And making an app work with N versions of the database (to address Chris' situation) is a loooooooot of overhead.

                          Jeremy Falcon

                          1 Reply Last reply
                          0
                          • C Chris Maunder

                            I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                            cheers Chris Maunder

                            C Offline
                            C Offline
                            CodeWraith
                            wrote on last edited by
                            #16

                            Chris Maunder wrote:

                            Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today?

                            Kindof. I always try to write very modular reusable components. For example I have a module that manages language resources in the database. I don't want to deal with that every time I start a new project. On the code side I have modules for the presentation tier, application logic, services, data access and entities. I only need to include these libraries and everything is ready - except the database. I do not have code to handle migrations, but when I run my project that now includes this module, it takes the database context and sets up the required tables if they are not there yet. But speaking of migrations: How about Entity Framework code first?

                            I have lived with several Zen masters - all of them were cats.

                            1 Reply Last reply
                            0
                            • C Chris Maunder

                              I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                              cheers Chris Maunder

                              G Offline
                              G Offline
                              GKP1992
                              wrote on last edited by
                              #17

                              Skynet :-D . Jokes apart, I do not think there exists a framework/suit intelligent enough to "fix" itself like that. But AI is progressing fast, soon you may get what you want. Or maybe they'll take over our jobs. Are you afraid? :laugh:

                              I am not the one who knocks. I never knock. In fact, I hate knocking.

                              1 Reply Last reply
                              0
                              • C Chris Maunder

                                I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                                cheers Chris Maunder

                                P Offline
                                P Offline
                                Phil J Pearson
                                wrote on last edited by
                                #18

                                I'm addressing only the "self-destructing" code part. I use a plugin system with my code so that plugins can implement features undreamed of when the original code was deployed. You just drop the plugin dll into the appropriate folder. I can envisage a system that would simply unload the plugin when it's no longer needed and delete the dll. The original code (once it supports the plugin system) doesn't need to change at all.

                                Phil


                                The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                                1 Reply Last reply
                                0
                                • C Chris Maunder

                                  An app rewriting itself is really the closest I could envision at the moment. An update is close, but it's a wholesale replacement, not a chameleon like morphing.

                                  cheers Chris Maunder

                                  H Offline
                                  H Offline
                                  Herbie Mountjoy
                                  wrote on last edited by
                                  #19

                                  This is getting onto the realms of TI-99s when code could overwrite itself. It was almost always a very bad idea.

                                  We're philosophical about power outages here. A.C. come, A.C. go.

                                  1 Reply Last reply
                                  0
                                  • C Chris Maunder

                                    You've just sent every DBA in the room screaming and clawing at their eyeballs ;) The situation is that the new code expects a column; the old version doesn't. Usually you can just update the database without the old code caring, then update the code and the new code picks up the new column. What if you can't run the migration until after you deploy the code because part of the migration will screw up, right royally, the old code? (The specific situation I have is a field being renamed then a new field being added with the previous name. Bad naming choices years ago...)

                                    cheers Chris Maunder

                                    A Offline
                                    A Offline
                                    Asday
                                    wrote on last edited by
                                    #20

                                    This is reasonably common over in the django world. You just do a double deployment. The first deployment migrates the data into a new column and transmogrifies it as needed. The second deployment brings the newer code and does the other half of the migration. Of course, the real solution is not to have whatever's going on be as coupled. Your application layer shouldn't care so much about your data layer.

                                    S 1 Reply Last reply
                                    0
                                    • C Chris Maunder

                                      I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                                      cheers Chris Maunder

                                      M Offline
                                      M Offline
                                      Marc Clifton
                                      wrote on last edited by
                                      #21

                                      Chris Maunder wrote:

                                      Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date?

                                      It's called Windows Update. ;)

                                      Latest Article - Class-less Coding - Minimalist C# and Why F# and Function Programming Has Some Advantages Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                      1 Reply Last reply
                                      0
                                      • A Asday

                                        This is reasonably common over in the django world. You just do a double deployment. The first deployment migrates the data into a new column and transmogrifies it as needed. The second deployment brings the newer code and does the other half of the migration. Of course, the real solution is not to have whatever's going on be as coupled. Your application layer shouldn't care so much about your data layer.

                                        S Offline
                                        S Offline
                                        Slacker007
                                        wrote on last edited by
                                        #22

                                        Asday wrote:

                                        the real solution is not to have whatever's going on be as coupled. Your application layer shouldn't care so much about your data layer.

                                        :thumbsup::thumbsup:

                                        1 Reply Last reply
                                        0
                                        • C Chris Maunder

                                          I had a thought. (I know: run, screaming, and hide your kids...) I often have to write code to deal with data migrations. We add a column to a database and we need to briefly have the code run on staging and production, running against the same database. So I add code like "if column exists, load column value". After the deploy is completed we remove the "if column exists" and redeploy. Has anyone ever heard of a system or language or framework that provides the means to have code self-destruct after a certain date? Does this even make sense? Am I few coffees short of a barista today? It just seemed...intriguing.

                                          cheers Chris Maunder

                                          D Offline
                                          D Offline
                                          Dan Neely
                                          wrote on last edited by
                                          #23

                                          If the intent is just to make sure the temp code is removed from your code base after it's done its job you could just put something in the codebase to trigger a build error in debug after enough time's past that you think it should be done to remind you to remove it. I've found a kludge[^] that is supposed to work like a C++ static assert. Wrap it in an `#if DEBUG` and you should be good to go.

                                          public void TempCodeExpiredAssert(DateTime expirationDate)
                                          {
                                          #if DEBUG
                                          byte a = DateTime.Now > expirationDate ? 0 : -1;

                                          #endif
                                          

                                          }

                                          PS, code is totally untested to avoid the no programming questions in the lounge rule.

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :rolleyes:

                                          :roll

                                          C 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups