Comments (4)
The initial submission for the --revert
flag was added a little over ten years ago (see f00b74d and e296a46) for schemas and sequences. Needless to say, a lot of water has gone under the bridge, in particular, the topological sorting of database objects (implemented mostly by @dvarrazzo).
If you look at the comments on f00b74d, you'll notice that the basic strategy was to "swap the top level database objects". What that means is that in Database::diff_map()
we swap self.db
(the old or "source" database) with self.ndb
(the new or "target" database). The problem is that the trees of objects "hanging" from the top level objects aren't exactly symmetrical, IIRC that was the case even before the topological ordering changes. The latter, however, introduced oid's because for the source database we fetch pg_depend
information, whereas the "target" is represented by a YAML file and lacks the oid's (since the YAML could've been generated from a different PG database). Before committing Daniele's changes in 2017 for 0.8.0, I was trying to think of a way to replace or supplement oid's by some other combination of identifiers, so that the "old" and "new" db's could be compared symmetrically (see #119).
Anyway, if you'd like to give it a try, I would suggest that you create one or two simple tests in tests/dbobject/test_table.py
, say, one to CREATE a table and verify that revert=True
generates code to DROP it, and vice versa (you can look at test_schema.py
and test_sequence.py
for the basic approach). Then, I'm afraid to say, you'll have to put on your debugging hat.
from pyrseas.
Thanks for the quick response! I'll see if I can have a go at it and toy around anytime soon
from pyrseas.
I've been toying around a bit and got a revert table renaming test to work (which has been the hardest to fix up until now) by hacking it a bit (see here).
The biggest issue there is that the oldnames have to get mapped from the old to the new target state. Would a suggested implementation of yours look similar to the hacky solution or are there other methods I could leverage to improve this?
from pyrseas.
As I recall, the oldname
attribute was introduced quite early (much before @dvarrazzo's topological sorting). It was my primitive attempt at trying to deal with RENAME-type changes and was never a satisfactory solution: it sort of worked in tests because it was easy to introduce the attribute in test data, but in practical use, it meant the user had to edit the YAML files (in order to generate the RENAME) but the edit could not be saved in a repository.
I'm fuzzy about what happened when Daniele worked on dependencies (I think he asked about oldname
either in GH or in separate emails), but think he skirted around it. @dvarrazzo, do you recall (or do you have any suggestions for Stijn)?
Perhaps what should be done is to "disable" oldname
and rename
processing, before trying to implement the "revert" functionality. Unfortunately, I count 28 calls to obj.set_oldname
and nine test_rename_*
tests so it may be somewhat cumbersome to attempt such a change, but it may clarify the issues behind trying to revert more straightforward changes, i.e., CREATE TABLE/DROP TABLE and vice versa.
from pyrseas.
Related Issues (20)
- ALTER SEQUENCE OWNER comes before CREATE TABLE HOT 3
- SSL Connection to remote database HOT 3
- datacopy CSV with null trailing columns not importing with -u HOT 7
- CREATE EXTENSION statements in the change script HOT 5
- [Contribution] Docker support HOT 2
- Sequences processing doesn't skip schemas defined with '-N' option. HOT 3
- dbtoyaml fails when dealing with extension-owned triggers/functions HOT 7
- Multiline Strings (source: |2) Output Unstable HOT 5
- Enable Github Discussions HOT 2
- Fails to Install: Error: pg_config executable not found HOT 5
- Error Using dbtoyaml With Supabase Schema HOT 67
- dbtoyaml Fails When PG Password Has Spaces (Improper Escaping) HOT 1
- Convert .travis.yml to GH Actions
- Fold pgdbconn back into Pyrseas HOT 1
- Key error when converting aggregate to YAML HOT 4
- plv8 to extension and fix reserved words in the primary key HOT 5
- Add REFERENCING tables in trigger HOT 3
- Support columns GENERATED AS (x) STORED HOT 2
- the yamltodb tool is not placing the names of schemas, tables and columns in double quotes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyrseas.