Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #8 from mark-burnett/postgres-janitor
Browse files Browse the repository at this point in the history
Add postgres janitor
  • Loading branch information
mark-burnett committed Jan 16, 2015
2 parents 93f5937 + 8cad3bb commit 6a8affb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions ptero_common/janitors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Janitor(object):
__metaclass__ = abc.ABCMeta

def __init__(self, url):
self.url = url
self.url_obj = urlparse(url)
self.sanitized_url = self.sanitize_url(self.url_obj)

Expand Down
20 changes: 20 additions & 0 deletions ptero_common/janitors/postgres_janitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .base import Janitor
import logging
import sqlalchemy


LOG = logging.getLogger(__name__)


class PostgresJanitor(Janitor):
ALLOWED_SCHEMES = {'postgres'}

def clean(self):
engine = sqlalchemy.create_engine(self.url)

meta = sqlalchemy.MetaData()
meta.reflect(bind=engine)

for name, table in meta.tables.iteritems():
LOG.debug('Deleting table %s', name)
engine.execute(table.drop())

0 comments on commit 6a8affb

Please sign in to comment.