From ab372e2ed8e1feeb74930a520c61e95767a72e97 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 1 Feb 2019 09:27:37 -0500 Subject: [PATCH] changes --- Pipfile | 14 ++++ Pipfile.lock | 160 ++++++++++++++++++++++++++++++++++++ README.md | 4 + migrations/0001.sql | 0 records_migrate/adapters.py | 42 ++++++++++ records_migrate/models.py | 16 ++++ t.py | 5 ++ 7 files changed, 241 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 migrations/0001.sql create mode 100644 records_migrate/adapters.py create mode 100644 t.py diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..4ed72fe --- /dev/null +++ b/Pipfile @@ -0,0 +1,14 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] +records = "*" +flake8 = "*" + +[packages] +docopt = "*" + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..cfb2aa9 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,160 @@ +{ + "_meta": { + "hash": { + "sha256": "fe88af79e6daea7246fa74c44179e7f83e1385ee8ff52c52907815184c88f0fd" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "docopt": { + "hashes": [ + "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491" + ], + "index": "pypi", + "version": "==0.6.2" + } + }, + "develop": { + "defusedxml": { + "hashes": [ + "sha256:24d7f2f94f7f3cb6061acb215685e5125fbcdc40a857eff9de22518820b0a4f4", + "sha256:702a91ade2968a82beb0db1e0766a6a273f33d4616a6ce8cde475d8e09853b20" + ], + "version": "==0.5.0" + }, + "docopt": { + "hashes": [ + "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491" + ], + "index": "pypi", + "version": "==0.6.2" + }, + "entrypoints": { + "hashes": [ + "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e58ecbb8dbe56d19", + "sha256:c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e99044204511f9ed547d48451" + ], + "version": "==0.3" + }, + "et-xmlfile": { + "hashes": [ + "sha256:614d9722d572f6246302c4491846d2c393c199cfa4edc9af593437691683335b" + ], + "version": "==1.0.1" + }, + "flake8": { + "hashes": [ + "sha256:09b9bb539920776da542e67a570a5df96ff933c9a08b62cfae920bcc789e4383", + "sha256:e0f8cd519cfc0072c0ee31add5def09d2b3ef6040b34dc426445c3af9b02163c" + ], + "index": "pypi", + "version": "==3.7.4" + }, + "jdcal": { + "hashes": [ + "sha256:948fb8d079e63b4be7a69dd5f0cd618a0a57e80753de8248fd786a8a20658a07", + "sha256:ea0a5067c5f0f50ad4c7bdc80abad3d976604f6fb026b0b3a17a9d84bb9046c9" + ], + "version": "==1.4" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + ], + "version": "==0.6.1" + }, + "odfpy": { + "hashes": [ + "sha256:596021f0519623ca8717331951c95e3b8d7b21e86edc7efe8cb650a0d0f59a2b" + ], + "version": "==1.4.0" + }, + "openpyxl": { + "hashes": [ + "sha256:a5285901fff7b99a011462f18506a4fbfe4055191149ff42f59345828f8cf7b2" + ], + "version": "==2.5.14" + }, + "pycodestyle": { + "hashes": [ + "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", + "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c" + ], + "version": "==2.5.0" + }, + "pyflakes": { + "hashes": [ + "sha256:5e8c00e30c464c99e0b501dc160b13a14af7f27d4dffb529c556e30a159e231d", + "sha256:f277f9ca3e55de669fba45b7393a1449009cff5a37d1af10ebb76c52765269cd" + ], + "version": "==2.1.0" + }, + "pyyaml": { + "hashes": [ + "sha256:3d7da3009c0f3e783b2c873687652d83b1bbfd5c88e9813fb7e5b03c0dd3108b", + "sha256:3ef3092145e9b70e3ddd2c7ad59bdd0252a94dfe3949721633e41344de00a6bf", + "sha256:40c71b8e076d0550b2e6380bada1f1cd1017b882f7e16f09a65be98e017f211a", + "sha256:558dd60b890ba8fd982e05941927a3911dc409a63dcb8b634feaa0cda69330d3", + "sha256:a7c28b45d9f99102fa092bb213aa12e0aaf9a6a1f5e395d36166639c1f96c3a1", + "sha256:aa7dd4a6a427aed7df6fb7f08a580d68d9b118d90310374716ae90b710280af1", + "sha256:bc558586e6045763782014934bfaf39d48b8ae85a2713117d16c39864085c613", + "sha256:d46d7982b62e0729ad0175a9bc7e10a566fc07b224d2c79fafb5e032727eaa04", + "sha256:d5eef459e30b09f5a098b9cea68bebfeb268697f78d647bd255a085371ac7f3f", + "sha256:e01d3203230e1786cd91ccfdc8f8454c8069c91bee3962ad93b87a4b2860f537", + "sha256:e170a9e6fcfd19021dd29845af83bb79236068bf5fd4df3327c1be18182b2531" + ], + "version": "==3.13" + }, + "records": { + "hashes": [ + "sha256:238cba35e8efbb724493bbb195bd027d9e78db4a978597969a7af0f722ac3686", + "sha256:6d060a2b44ecc198d4e86efd5dab8558a2581b4019970bd8839e1604a243f57e" + ], + "index": "pypi", + "version": "==0.5.2" + }, + "sqlalchemy": { + "hashes": [ + "sha256:52a42dbf02d0562d6e90e7af59f177f1cc027e72833cc29c3a821eefa009c71d" + ], + "version": "==1.2.17" + }, + "tablib": { + "hashes": [ + "sha256:b8cf50a61d66655229993f2ee29220553fb2c80403479f8e6de77c0c24649d87" + ], + "version": "==0.12.1" + }, + "unicodecsv": { + "hashes": [ + "sha256:018c08037d48649a0412063ff4eda26eaa81eff1546dbffa51fa5293276ff7fc" + ], + "version": "==0.14.1" + }, + "xlrd": { + "hashes": [ + "sha256:546eb36cee8db40c3eaa46c351e67ffee6eeb5fa2650b71bc4c758a29a1b29b2", + "sha256:e551fb498759fa3a5384a94ccd4c3c02eb7c00ea424426e212ac0c57be9dfbde" + ], + "version": "==1.2.0" + }, + "xlwt": { + "hashes": [ + "sha256:a082260524678ba48a297d922cc385f58278b8aa68741596a87de01a9c628b2e", + "sha256:c59912717a9b28f1a3c2a98fd60741014b06b043936dcecbc113eaaada156c88" + ], + "version": "==1.3.0" + } + } +} diff --git a/README.md b/README.md index 1fcda7a..d174ffc 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,7 @@ A migration system for the [Records](https://github.com/kennethreitz/records) Py $ records-migrate apply Applied migration 3/5... + +## Considerations + +- Don't base migration order on file creation time, as Heroku strips the data on deploy. diff --git a/migrations/0001.sql b/migrations/0001.sql new file mode 100644 index 0000000..e69de29 diff --git a/records_migrate/adapters.py b/records_migrate/adapters.py new file mode 100644 index 0000000..208458e --- /dev/null +++ b/records_migrate/adapters.py @@ -0,0 +1,42 @@ +import os + +from .models import Migration + +class MigrationAdapter: + def __init__(self, db, *, _dir="migrations", default_format="{:06d}"): + # Make path of dir absolute. + _dir = os.path.abspath(_dir) + + # Create the migration directory, if it doesn't exist + os.makedirs(_dir, exist_ok=True) + + # The migrations directory. + self.migrations_dir = _dir + + # The database. + self.db = db + + @property + def files(self): + """Returns a list of file names in the migrations directory, in order.""" + def gen(): + for root, dirs, files in os.walk(self.migrations_dir, topdown=True, followlinks=True): + for _file in files: + # Yield the file name. + yield f"{root}{os.path.sep}{_file}" + + return [g for g in gen()] + + def load(self): + def gen(): + for _file in self.files: + yield Migration(path=_file, adapter=self) + + return [g for g in gen()] + + def query(self, query): + return self.db.query(query) + + @property + def last_migration_applied(self): + raise NotImplementedError diff --git a/records_migrate/models.py b/records_migrate/models.py index e69de29..24479e7 100644 --- a/records_migrate/models.py +++ b/records_migrate/models.py @@ -0,0 +1,16 @@ +class Migration: + def __init__(self, *, path, adapter): + self.path = path + self.adapter = adapter + + def __repr__(self): + return f"" + + def queries(self): + for _ in os.walk(self.path): + print(_) + + def text(self): + """Returns the text of the query.""" + with open(self.path, 'r') as f: + return f.read() diff --git a/t.py b/t.py new file mode 100644 index 0000000..598bb61 --- /dev/null +++ b/t.py @@ -0,0 +1,5 @@ +from records_migrate.adapters import MigrationAdapter + +a = MigrationAdapter(db=None) +for file in a.load(): + print(file)