relations-postgresql 0.6.3__tar.gz → 0.6.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/PKG-INFO +11 -3
  2. relations_postgresql-0.6.5/lib/relations_postgresql/column.py +95 -0
  3. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql.egg-info/PKG-INFO +11 -3
  4. relations_postgresql-0.6.5/lib/relations_postgresql.egg-info/requires.txt +1 -0
  5. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/setup.py +9 -2
  6. relations_postgresql-0.6.3/lib/relations_postgresql/column.py +0 -50
  7. relations_postgresql-0.6.3/lib/relations_postgresql.egg-info/requires.txt +0 -1
  8. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/LICENSE.txt +0 -0
  9. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/README.md +0 -0
  10. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/__init__.py +0 -0
  11. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/clause.py +0 -0
  12. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/criteria.py +0 -0
  13. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/criterion.py +0 -0
  14. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/ddl.py +0 -0
  15. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/expression.py +0 -0
  16. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/index.py +0 -0
  17. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/query.py +0 -0
  18. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/sql.py +0 -0
  19. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql/table.py +0 -0
  20. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql.egg-info/SOURCES.txt +0 -0
  21. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql.egg-info/dependency_links.txt +0 -0
  22. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/lib/relations_postgresql.egg-info/top_level.txt +0 -0
  23. {relations_postgresql-0.6.3 → relations_postgresql-0.6.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: relations-postgresql
3
- Version: 0.6.3
3
+ Version: 0.6.5
4
4
  Home-page: https://github.com/relations-dil/python-relations-postgresql
5
5
  Author: Gaffer Fitch
6
6
  Author-email: relations@gaf3.com
@@ -8,7 +8,15 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE.txt
11
- Requires-Dist: relations-sql>=0.6.8
11
+ Requires-Dist: relations-sql>=0.6.11
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: classifier
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: home-page
18
+ Dynamic: license-file
19
+ Dynamic: requires-dist
12
20
 
13
21
  # relations-postgresql
14
22
 
@@ -0,0 +1,95 @@
1
+ """
2
+ Module for Column DDL
3
+ """
4
+
5
+ # pylint: disable=unused-argument
6
+
7
+ import relations_sql
8
+ import relations_postgresql
9
+
10
+ class COLUMN(relations_postgresql.DDL, relations_sql.COLUMN):
11
+ """
12
+ COLUMN DDL
13
+ """
14
+
15
+ KINDS = {
16
+ "bool": "BOOLEAN",
17
+ "int": "INT8",
18
+ "float": "FLOAT8",
19
+ "str": "VARCHAR(255)",
20
+ "json": "JSONB"
21
+ }
22
+
23
+ COLUMN_NAME = relations_postgresql.COLUMN_NAME
24
+
25
+ STORE = """RENAME %s TO %s"""
26
+ AUTO = """BIGSERIAL"""
27
+ EXTRACT = """GENERATED ALWAYS AS ((%s)::%s) STORED"""
28
+ SET_DEFAULT = """ALTER %s SET DEFAULT %s"""
29
+ UNSET_DEFAULT = """ALTER %s DROP DEFAULT"""
30
+ SET_NONE = """ALTER %s SET NOT NULL"""
31
+ UNSET_NONE = """ALTER %s DROP NOT NULL"""
32
+
33
+ def cast(self, kind, length):
34
+ """
35
+ Get the type of a kind, a str with a length being that long
36
+ """
37
+
38
+ if kind == "str" and length:
39
+ return f"VARCHAR({length})"
40
+
41
+ return self.KINDS.get(kind, self.KINDS["json"])
42
+
43
+ def create(self, **kwargs):
44
+ """
45
+ CREATE DLL, a str with a length being that long
46
+ """
47
+
48
+ super().create(**kwargs)
49
+
50
+ if self.migration.get("kind") == "str" and self.migration.get("length") and "__" not in self.migration["store"]:
51
+ self.sql = self.sql.replace(self.KINDS["str"], self.cast("str", self.migration["length"]), 1)
52
+
53
+ def extract(self, kind, sql, **kwargs):
54
+ """
55
+ Get extract DDL
56
+ """
57
+
58
+ sql.append(self.KINDS.get(self.migration['kind'], self.KINDS["json"]))
59
+
60
+ name, path = self.COLUMN_NAME.split(self.migration["store"])
61
+ sql.append(self.EXTRACT % (self.PATH % (self.quote(name), self.str(self.walk(path))), self.KINDS.get(kind, self.KINDS["json"])))
62
+
63
+ def kind(self, sql):
64
+ """
65
+ Modifies the kind
66
+ """
67
+
68
+ cast = self.cast(
69
+ self.migration.get("kind", self.definition["kind"]),
70
+ self.migration.get("length", self.definition.get("length"))
71
+ )
72
+
73
+ sql.append(f'ALTER {self.name()} TYPE {cast} USING {self.name()}::{cast}')
74
+
75
+ def modify(self, indent=0, count=0, pad=' ', **kwargs):
76
+ """
77
+ MODIFY DLL, an id that stops being an auto int also loses the sequence default BIGSERIAL gave it, and a
78
+ str changing its length gets a new kind
79
+ """
80
+
81
+ if "length" in self.migration and "kind" not in self.migration and self.definition["kind"] == "str":
82
+ self.migration = {**self.migration, "kind": "str"}
83
+
84
+ super().modify(indent=indent, count=count, pad=pad, **kwargs)
85
+
86
+ migration = self.migration
87
+
88
+ stops = migration.get("auto") is False or migration.get("kind", "int") != "int"
89
+
90
+ if self.definition.get("auto") and "default" not in migration and stops:
91
+
92
+ current = pad * (count * indent)
93
+ delimitter = f",\n{current}" if indent else ','
94
+
95
+ self.sql = delimitter.join(filter(None, [self.sql, self.UNSET_DEFAULT % self.name()]))
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: relations-postgresql
3
- Version: 0.6.3
3
+ Version: 0.6.5
4
4
  Home-page: https://github.com/relations-dil/python-relations-postgresql
5
5
  Author: Gaffer Fitch
6
6
  Author-email: relations@gaf3.com
@@ -8,7 +8,15 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE.txt
11
- Requires-Dist: relations-sql>=0.6.8
11
+ Requires-Dist: relations-sql>=0.6.11
12
+ Dynamic: author
13
+ Dynamic: author-email
14
+ Dynamic: classifier
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: home-page
18
+ Dynamic: license-file
19
+ Dynamic: requires-dist
12
20
 
13
21
  # relations-postgresql
14
22
 
@@ -0,0 +1 @@
1
+ relations-sql>=0.6.11
@@ -1,13 +1,20 @@
1
1
  #!/usr/bin/env python
2
2
 
3
+ import os
3
4
  from setuptools import setup
4
5
 
5
6
  with open("README.md", "r") as readme_file:
6
7
  long_description = readme_file.read()
7
8
 
9
+ version = os.environ.get("BUILD_VERSION")
10
+
11
+ if version is None:
12
+ with open("VERSION", "r") as version_file:
13
+ version = version_file.read().strip()
14
+
8
15
  setup(
9
16
  name="relations-postgresql",
10
- version="0.6.3",
17
+ version=version,
11
18
  package_dir = {'': 'lib'},
12
19
  py_modules = [
13
20
  'relations_postgresql',
@@ -23,7 +30,7 @@ setup(
23
30
  'relations_postgresql.table'
24
31
  ],
25
32
  install_requires=[
26
- 'relations-sql>=0.6.8'
33
+ 'relations-sql>=0.6.11'
27
34
  ],
28
35
  url="https://github.com/relations-dil/python-relations-postgresql",
29
36
  author="Gaffer Fitch",
@@ -1,50 +0,0 @@
1
- """
2
- Module for Column DDL
3
- """
4
-
5
- # pylint: disable=unused-argument
6
-
7
- import relations_sql
8
- import relations_postgresql
9
-
10
- class COLUMN(relations_postgresql.DDL, relations_sql.COLUMN):
11
- """
12
- COLUMN DDL
13
- """
14
-
15
- KINDS = {
16
- "bool": "BOOLEAN",
17
- "int": "INT8",
18
- "float": "FLOAT8",
19
- "str": "VARCHAR(255)",
20
- "json": "JSONB"
21
- }
22
-
23
- COLUMN_NAME = relations_postgresql.COLUMN_NAME
24
-
25
- STORE = """RENAME %s TO %s"""
26
- AUTO = """BIGSERIAL"""
27
- EXTRACT = """GENERATED ALWAYS AS ((%s)::%s) STORED"""
28
- SET_DEFAULT = """ALTER %s SET DEFAULT %s"""
29
- UNSET_DEFAULT = """ALTER %s DROP DEFAULT"""
30
- SET_NONE = """ALTER %s SET NOT NULL"""
31
- UNSET_NONE = """ALTER %s DROP NOT NULL"""
32
-
33
- def extract(self, kind, sql, **kwargs):
34
- """
35
- Get extract DDL
36
- """
37
-
38
- sql.append(self.KINDS.get(self.migration['kind'], self.KINDS["json"]))
39
-
40
- name, path = self.COLUMN_NAME.split(self.migration["store"])
41
- sql.append(self.EXTRACT % (self.PATH % (self.quote(name), self.str(self.walk(path))), self.KINDS.get(kind, self.KINDS["json"])))
42
-
43
- def kind(self, sql):
44
- """
45
- Modifies the kind
46
- """
47
-
48
- cast = self.KINDS.get(self.migration.get("kind", self.definition["kind"]), self.KINDS["json"])
49
-
50
- sql.append(f'ALTER {self.name()} TYPE {cast} USING {self.name()}::{cast}')
@@ -1 +0,0 @@
1
- relations-sql>=0.6.8