What is the Best Way to Rename Persistent Classes which Already have Data?
Hello!
Suppose I have a package with classes which I want to rename. All these classes are persistent and they already have a lot of data stored.
The best I can think of to do is the following:
- Duplicate class definitions of old classes, rename each of them and save
- Write a routine to copy (duplicate) all the data from old classes to new ones. (which is not trivial at some point)
- Refactor all the application's code to use new classes. (which may not be trivial at some point too)
- Test the things above
- Load new code to live environment and launch the script
- Hope that
5.
finishes successfully. If not, revert the code and jump to4.
Are there any better approaches than this? Maybe any utilities or better methods of renaming a class. I read this and this, but I am still not sure whether, say, instead of 2.
a simple globals export/renaming/import won't corrupt the data (as the column numbers may change, etc).
Thank you for any advice!
A few recommendations:
#2) save you original Global as you do otherwise. [Just to be Save]
#1) In Studio Copy class has a checkbox to copy Storage Definition (=Globals) . Set it.
In the new class add ClassParameter MANAGEDEXTENT=0 ;
/// to ignore this class. If set to 1 then the Extent Manager will register globals used by
/// the class and detect collisions. Unmanaged extents (MANAGEDEXTENT = 0) are not checked.
/// Currently, only classes using default storage (%Library.CacheStorage) can be managed.
Parameter MANAGEDEXTENT As INTEGER [ Constraint = "0,1", Flags = ENUM ] = 1;
So the old and the new class use the same Globals.
Now go on with #3 to #6
If you miss something in refactoring the damage should be limited as you just change names not the Storage in Globals.
Assuming the change of ClassName is all you do.
Interesting about MANAGEDEXTENT.
I'm curious, what are the typical use cases, when MANAGEDEXTENT can be helpful?
Thank you very much, Robert! Good to know about
MANAGEDEXTENT
, I have never heard of it.Do you think it's okay just to copy storage definition/globals as people suggest below? (to duplicate globals data and alter storage definition to use new globals)
Thank you, Dan!
I was pretty sure to miss some cases.
SOID is probably the one nobody else would be aware of that it exists.
Daniel, thank you for these important points.
When you want to have two or more classes pointing to the same storage. Sometimes it can be useful to have one persistent class with full definition and another with only a few properties. I used this approach to test indices building on a test class - it does not affect existing class and it's indices.
similar in practice if you run bookkeeping as a service.
Using Government class
master has full access and has the responsibility for the content. Using Work class
clients have just read access to most fields. Using Client class.
I didn't say tax control doesn't see everything.
Why is it not trivial? If you're not changing class definition three merges per class should be enough.
Also check that storage definition in the new class is the same as in old class, only pointing to the new globals.
MANAGEDEXTENT=0 may be easier to do, but it raises the risk of accidentally deleting old globals (what are these globals not corresponding to any class? Let's free some space)
Interesting. Never knew about MANAGEDEXTENT parameter, mentioned by @Robert.Cemper. And yes, backup your globals.
But in your case, @Nikita.Savchenko, I would go with the following. Consider you have class A and rename it to class B.
1 - is yours.
1a. When duplicating be SURE, that you take class storage definition from A, not generate it because of compile. Change places with global A to global B in storage definition and compile class B.
It's MANDATORY to take class A storage def to B class definition and compile after that and not use generated storage definition in class B.
2. Merge data globals from class A to class B. E.g.
3-4 - yours.
5. Load new scripts and make global merges and test.
6. Is yours.
Renaming a persistent class is complicated a few things:
-Dan
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue