Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 0 additions & 190 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,211 +1,21 @@
sudo: false
language: python
python:
- 2.6
- 2.7
- 3.2
- 3.3
- 3.4
- 3.5
- 3.6
env:
- SQLOBJECT='sqlobject>=1.5.0,<1.6.0' DB='all'
- SQLOBJECT='sqlobject>=1.6.0,<1.7.0' DB='all'
- SQLOBJECT='sqlobject>=1.7.0,<1.8.0' DB='all'
- SQLOBJECT='sqlobject>=2.0.0,<2.1.0' DB='all'
- SQLOBJECT='sqlobject>=2.1.0,<2.2.0' DB='all'
- SQLOBJECT='sqlobject>=2.2.0,<2.3.0' DB='all'
- SQLOBJECT='sqlobject>=3.0.0,<3.1.0' DB='all'
- SQLOBJECT='sqlobject>=3.1.0,<3.2.0' DB='all'
- SQLOBJECT='sqlobject>=3.2.0,<3.3.0' DB='all'
- SQLOBJECT='sqlobject>=3.3.0,<3.4.0' DB='all'
- PEEWEE='peewee>=2.2.0,<2.3.0' DB='all'
- PEEWEE='peewee>=2.3.0,<2.4.0' DB='all'
- PEEWEE='peewee>=2.4.0,<2.5.0' DB='all'
- PEEWEE='peewee>=2.5.0,<2.6.0' DB='all'
- PEEWEE='peewee>=2.6.0,<2.7.0' DB='all'
- PEEWEE='peewee>=2.7.0,<2.8.0' DB='all'
- PEEWEE='peewee>=2.8.0,<2.9.0' DB='all'
- PEEWEE='peewee>=2.9.0,<2.10.0' DB='all'
- PONY='pony>=0.5.0,<0.6.0' DB='all'
- PONY='pony>=0.6.0,<0.7.0' DB='all'
- PONY='pony>=0.7.0,<0.8.0' DB='all'
- SQLALCHEMY='sqlalchemy>=0.8.0,<0.9.0' DB='all'
- SQLALCHEMY='sqlalchemy>=0.9.0,<0.10.0' DB='all'
- SQLALCHEMY='sqlalchemy>=1.0.0,<1.1.0' DB='all'
- SQLALCHEMY='sqlalchemy>=1.1.0,<1.2.0' DB='all'
- DJANGO='django>=1.4.0,<1.5.0' DB='all'
- DJANGO='django>=1.5.0,<1.6.0' DB='all'
- DJANGO='django>=1.6.0,<1.7.0' DB='all'
- DJANGO='django>=1.7.0,<1.8.0' DB='all'
- DJANGO='django>=1.8.0,<1.9.0' DB='all'
- DJANGO='django>=1.9.0,<1.10.0' DB='all'
- DJANGO='django>=1.10.0,<1.11.0' DB='all'
- DJANGO='django>=1.11.0,<1.12.0' DB='all'
matrix:
fast_finish: true
exclude:
- python: 3.2
env: SQLOBJECT='sqlobject>=1.5.0,<1.6.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=1.6.0,<1.7.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=1.7.0,<1.8.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=2.0.0,<2.1.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=2.1.0,<2.2.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=2.2.0,<2.3.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=3.0.0,<3.1.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=3.1.0,<3.2.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=3.2.0,<3.3.0' DB='all'
- python: 3.2
env: SQLOBJECT='sqlobject>=3.3.0,<3.4.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=1.5.0,<1.6.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=1.6.0,<1.7.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=1.7.0,<1.8.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=2.0.0,<2.1.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=2.1.0,<2.2.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=2.2.0,<2.3.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=3.0.0,<3.1.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=3.1.0,<3.2.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=3.2.0,<3.3.0' DB='all'
- python: 3.3
env: SQLOBJECT='sqlobject>=3.3.0,<3.4.0' DB='all'
- python: 3.4
env: SQLOBJECT='sqlobject>=1.5.0,<1.6.0' DB='all'
- python: 3.4
env: SQLOBJECT='sqlobject>=1.6.0,<1.7.0' DB='all'
- python: 3.4
env: SQLOBJECT='sqlobject>=1.7.0,<1.8.0' DB='all'
- python: 3.4
env: SQLOBJECT='sqlobject>=2.0.0,<2.1.0' DB='all'
- python: 3.4
env: SQLOBJECT='sqlobject>=2.1.0,<2.2.0' DB='all'
- python: 3.4
env: SQLOBJECT='sqlobject>=2.2.0,<2.3.0' DB='all'
- python: 3.5
env: SQLOBJECT='sqlobject>=1.5.0,<1.6.0' DB='all'
- python: 3.5
env: SQLOBJECT='sqlobject>=1.6.0,<1.7.0' DB='all'
- python: 3.5
env: SQLOBJECT='sqlobject>=1.7.0,<1.8.0' DB='all'
- python: 3.5
env: SQLOBJECT='sqlobject>=2.0.0,<2.1.0' DB='all'
- python: 3.5
env: SQLOBJECT='sqlobject>=2.1.0,<2.2.0' DB='all'
- python: 3.5
env: SQLOBJECT='sqlobject>=2.2.0,<2.3.0' DB='all'
- python: 3.6
env: SQLOBJECT='sqlobject>=1.5.0,<1.6.0' DB='all'
- python: 3.6
env: SQLOBJECT='sqlobject>=1.6.0,<1.7.0' DB='all'
- python: 3.6
env: SQLOBJECT='sqlobject>=1.7.0,<1.8.0' DB='all'
- python: 3.6
env: SQLOBJECT='sqlobject>=2.0.0,<2.1.0' DB='all'
- python: 3.6
env: SQLOBJECT='sqlobject>=2.1.0,<2.2.0' DB='all'
- python: 3.6
env: SQLOBJECT='sqlobject>=2.2.0,<2.3.0' DB='all'
- python: 2.6
env: DJANGO='django>=1.7.0,<1.8.0' DB='all'
- python: 2.6
env: DJANGO='django>=1.8.0,<1.9.0' DB='all'
- python: 2.6
env: DJANGO='django>=1.9.0,<1.10.0' DB='all'
- python: 2.6
env: DJANGO='django>=1.10.0,<1.11.0' DB='all'
- python: 2.6
env: DJANGO='django>=1.11.0,<1.12.0' DB='all'
- python: 3.2
env: DJANGO='django>=1.4.0,<1.5.0' DB='all'
- python: 3.2
env: DJANGO='django>=1.9.0,<1.10.0' DB='all'
- python: 3.2
env: DJANGO='django>=1.10.0,<1.11.0' DB='all'
- python: 3.2
env: DJANGO='django>=1.11.0,<1.12.0' DB='all'
- python: 3.3
env: DJANGO='django>=1.4.0,<1.5.0' DB='all'
- python: 3.3
env: DJANGO='django>=1.9.0,<1.10.0' DB='all'
- python: 3.3
env: DJANGO='django>=1.10.0,<1.11.0' DB='all'
- python: 3.3
env: DJANGO='django>=1.11.0,<1.12.0' DB='all'
- python: 3.4
env: DJANGO='django>=1.4.0,<1.5.0' DB='all'
- python: 3.5
env: DJANGO='django>=1.4.0,<1.5.0' DB='all'
- python: 3.5
env: DJANGO='django>=1.5.0,<1.6.0' DB='all'
- python: 3.5
env: DJANGO='django>=1.6.0,<1.7.0' DB='all'
- python: 3.5
env: DJANGO='django>=1.7.0,<1.8.0' DB='all'
- python: 3.6
env: DJANGO='django>=1.4.0,<1.5.0' DB='all'
- python: 3.6
env: DJANGO='django>=1.5.0,<1.6.0' DB='all'
- python: 3.6
env: DJANGO='django>=1.6.0,<1.7.0' DB='all'
- python: 3.6
env: DJANGO='django>=1.7.0,<1.8.0' DB='all'
- python: 2.6
env: PONY='pony>=0.6.0,<0.7.0' DB='all'
- python: 2.6
env: PONY='pony>=0.7.0,<0.8.0' DB='all'
- python: 3.2
env: PONY='pony>=0.5.0,<0.6.0' DB='all'
- python: 3.2
env: PONY='pony>=0.6.0,<0.7.0' DB='all'
- python: 3.2
env: PONY='pony>=0.7.0,<0.8.0' DB='all'
- python: 3.3
env: PONY='pony>=0.5.0,<0.6.0' DB='all'
- python: 3.4
env: PONY='pony>=0.5.0,<0.6.0' DB='all'
- python: 3.5
env: PONY='pony>=0.5.0,<0.6.0' DB='all'
- python: 3.6
env: PONY='pony>=0.5.0,<0.6.0' DB='all'
- python: 3.6
env: PONY='pony>=0.6.0,<0.7.0' DB='all'
- python: 3.2
env: PEEWEE='peewee>=2.8.0,<2.9.0' DB='all'
- python: 3.2
env: PEEWEE='peewee>=2.9.0,<2.10.0' DB='all'
- python: 3.3
env: PEEWEE='peewee>=2.8.0,<2.9.0' DB='all'
- python: 3.3
env: PEEWEE='peewee>=2.9.0,<2.10.0' DB='all'
before_script:
- psql -c 'create database architect;' -U postgres
- mysql -e 'create database architect;' -u root
install:
- travis_retry pip install -r tests/requirements.txt
- travis_retry pip install coveralls psycopg2 pymysql
- if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then travis_retry pip install unittest2 argparse; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]]; then travis_retry pip install 'coverage<4.0' 'pymysql<0.7.0'; fi
- if [[ $DJANGO ]]; then travis_retry pip install $DJANGO; fi
- if [[ $PEEWEE ]]; then travis_retry pip install $PEEWEE; fi
- if [[ $PONY ]]; then travis_retry pip install $PONY; fi
- if [[ $SQLALCHEMY ]]; then travis_retry pip install $SQLALCHEMY; fi
- if [[ $SQLOBJECT ]]; then travis_retry pip install $SQLOBJECT; fi
script:
- nosetests --with-coverage --cover-erase --cover-package=architect
after_success:
Expand Down
1 change: 1 addition & 0 deletions architect/databases/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, model, **meta):
self.column_value = meta['column_value']
self.column_name = meta['column']
self.pks = meta['pk'] if isinstance(meta['pk'], list) else [meta['pk']]
self.return_null = meta.get('return_null', False)

def prepare(self):
"""
Expand Down
15 changes: 10 additions & 5 deletions architect/databases/postgresql/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def prepare(self):

definitions[definition] = '\n'.join(definitions[definition]).format(**formatters)

return self.database.execute("""
execute_sql = """
-- We need to create a before insert function
CREATE OR REPLACE FUNCTION {{safe_tablename}}_insert_child()
RETURNS TRIGGER AS $$
Expand All @@ -72,7 +72,7 @@ def prepare(self):
END;

EXECUTE 'INSERT INTO ' || tablename || ' VALUES (($1).*);' USING NEW;
RETURN NEW;
RETURN {{return_val}};
END;
$$ LANGUAGE plpgsql SECURITY DEFINER;

Expand All @@ -90,7 +90,9 @@ def prepare(self):
FOR EACH ROW EXECUTE PROCEDURE {{safe_tablename}}_insert_child();
END IF;
END $$;

"""
if not self.return_null:
execute_sql += """
-- Then we create a function to delete duplicate row from the master table after insert
CREATE OR REPLACE FUNCTION {{safe_tablename}}_delete_master()
RETURNS TRIGGER AS $$
Expand All @@ -114,11 +116,14 @@ def prepare(self):
FOR EACH ROW EXECUTE PROCEDURE {{safe_tablename}}_delete_master();
END IF;
END $$;
""".format(**definitions).format(
"""

return self.database.execute(execute_sql.format(**definitions).format(
pk=' AND '.join('{pk} = NEW.{pk}'.format(pk=pk) for pk in self.pks),
parent_table=self.table,
column='"{0}"'.format(self.column_name),
safe_tablename=self.safe_tablename
safe_tablename=self.safe_tablename,
return_val='NULL' if self.return_null else 'NEW'
))

def exists(self):
Expand Down
61 changes: 32 additions & 29 deletions tests/models/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,55 +51,58 @@

# Generation of entities for date range partitioning
for item in ('day', 'week', 'month', 'year'):
class Meta(object):
app_label = 'test'
db_table = 'test_rangedate{0}'.format(item)

name = '{0}RangeDate{1}'.format(dbname, item.capitalize())
partition = install('partition', type='range', subtype='date', constraint=item, column='created')

locals()[name] = partition(type(name, (models.Model,), {
'__module__': 'test.models',
'name': models.CharField(max_length=255),
'created': models.DateTimeField(null=True),
'Meta': Meta,
'db': database,
}))

if database == 'pgsql':
# Generation of entities for integer range partitioning
for item in ('2', '5'):
for return_null in (True, False):
class Meta(object):
app_label = 'test'
db_table = 'test_rangeinteger{0}'.format(item)
db_table = 'test_rangedate{0}{1}'.format(item, '_return_null' if return_null else '')

name = '{0}RangeInteger{1}'.format(dbname, item)
partition = install('partition', type='range', subtype='integer', constraint=item, column='num')
name = '{0}RangeDate{1}{2}'.format(dbname, item.capitalize(), 'ReturnNULL' if return_null else '')
partition = install('partition', type='range', subtype='date', constraint=item, column='created', return_null=return_null)

locals()[name] = partition(type(name, (models.Model,), {
'__module__': 'test.models',
'name': models.CharField(max_length=255),
'num': models.IntegerField(null=True),
'created': models.DateTimeField(null=True),
'Meta': Meta,
'db': database,
}))

# Generation of entities for string range partitioning
for subtype in ('string_firstchars', 'string_lastchars'):
for item in ('2', '5'):
if database == 'pgsql':
# Generation of entities for integer range partitioning
for item in ('2', '5'):
for return_null in (True, False):
class Meta(object):
app_label = 'test'
db_table = 'test_range{0}{1}'.format(subtype, item)
db_table = 'test_rangeinteger{0}{1}'.format(item, '_return_null' if return_null else '')

name = '{0}Range{1}{2}'.format(dbname, ''.join(s.capitalize() for s in subtype.split('_')), item)
partition = install('partition', type='range', subtype=subtype, constraint=item, column='title')
name = '{0}RangeInteger{1}{2}'.format(dbname, item, 'ReturnNULL' if return_null else '')
partition = install('partition', type='range', subtype='integer', constraint=item, column='num', return_null=return_null)

locals()[name] = partition(type(name, (models.Model,), {
'__module__': 'test.models',
'name': models.CharField(max_length=255),
'title': models.CharField(max_length=255, null=True),
'num': models.IntegerField(null=True),
'Meta': Meta,
'db': database,
}))

# Generation of entities for string range partitioning
for subtype in ('string_firstchars', 'string_lastchars'):
for item in ('2', '5'):
for return_null in (True, False):
class Meta(object):
app_label = 'test'
db_table = 'test_range{0}{1}{2}'.format(subtype, item, '_return_null' if return_null else '')

name = '{0}Range{1}{2}{3}'.format(dbname, ''.join(s.capitalize() for s in subtype.split('_')), item, 'ReturnNULL' if return_null else '')
partition = install('partition', type='range', subtype=subtype, constraint=item, column='title', return_null=return_null)

locals()[name] = partition(type(name, (models.Model,), {
'__module__': 'test.models',
'name': models.CharField(max_length=255),
'title': models.CharField(max_length=255, null=True),
'Meta': Meta,
'db': database,
}))

management.call_command(command, database=database, run_syncdb=True, verbosity=0, interactive=False)
Loading