-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from CodeForAfrica/chore-upgrade-to-ckan-2.8
Chore upgrade to ckan 2.8
- Loading branch information
Showing
12 changed files
with
181 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,6 @@ ENV/ | |
ckan | ||
ckan/ | ||
ckan-*.tar.gz | ||
|
||
# Env | ||
env* | ||
!env.tmpl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM codeforafrica/ckan:2.7.6 | ||
FROM codeforafrica/ckan:2.8.3 | ||
|
||
EXPOSE 5000/tcp | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# encoding: utf-8 | ||
|
||
import datetime | ||
|
||
from paste.deploy.converters import asbool | ||
from ckan.common import config | ||
"""SQLAlchemy Metadata and Session object""" | ||
from sqlalchemy import MetaData, and_ | ||
import sqlalchemy.orm as orm | ||
from sqlalchemy.orm.session import SessionExtension | ||
|
||
import extension | ||
import ckan.lib.activity_streams_session_extension as activity | ||
|
||
__all__ = ['Session', 'engine_is_sqlite', 'engine_is_pg'] | ||
|
||
|
||
class CkanCacheExtension(SessionExtension): | ||
''' This extension checks what tables have been affected by | ||
database access and allows us to act on them. Currently this is | ||
used by the page cache to flush the cache when data in the database | ||
is altered. ''' | ||
|
||
def __init__(self, *args, **kw): | ||
super(CkanCacheExtension, self).__init__(*args, **kw) | ||
|
||
def after_commit(self, session): | ||
if hasattr(session, '_object_cache'): | ||
oc = session._object_cache | ||
oc_list = oc['new'] | ||
oc_list.update(oc['changed']) | ||
oc_list.update(oc['deleted']) | ||
objs = set() | ||
for item in oc_list: | ||
objs.add(item.__class__.__name__) | ||
|
||
|
||
class CkanSessionExtension(SessionExtension): | ||
|
||
def before_flush(self, session, flush_context, instances): | ||
if not hasattr(session, '_object_cache'): | ||
session._object_cache= {'new': set(), | ||
'deleted': set(), | ||
'changed': set()} | ||
|
||
changed = [obj for obj in session.dirty if | ||
session.is_modified(obj, include_collections=False, passive=True)] | ||
|
||
session._object_cache['new'].update(session.new) | ||
session._object_cache['deleted'].update(session.deleted) | ||
session._object_cache['changed'].update(changed) | ||
|
||
|
||
def before_commit(self, session): | ||
session.flush() | ||
try: | ||
obj_cache = session._object_cache | ||
revision = session.revision | ||
except AttributeError: | ||
return | ||
if getattr(session, 'revisioning_disabled', False): | ||
return | ||
new = obj_cache['new'] | ||
changed = obj_cache['changed'] | ||
deleted = obj_cache['deleted'] | ||
for obj in new | changed | deleted: | ||
if not hasattr(obj, '__revision_class__'): | ||
continue | ||
revision_cls = obj.__revision_class__ | ||
revision_table = orm.class_mapper(revision_cls).mapped_table | ||
## when a normal active transaction happens | ||
|
||
### this is an sql statement as we do not want it in object cache | ||
session.execute( | ||
revision_table.update().where( | ||
and_(revision_table.c.id == obj.id, | ||
revision_table.c.current == True) | ||
).values(current=False) | ||
) | ||
|
||
q = session.query(revision_cls) | ||
q = q.filter_by(expired_timestamp=datetime.datetime(9999, 12, 31), id=obj.id) | ||
results = q.all() | ||
for rev_obj in results: | ||
values = {} | ||
if rev_obj.revision_id == revision.id: | ||
values['revision_timestamp'] = revision.timestamp | ||
else: | ||
values['expired_timestamp'] = revision.timestamp | ||
session.execute( | ||
revision_table.update().where( | ||
and_(revision_table.c.id == rev_obj.id, | ||
revision_table.c.revision_id == rev_obj.revision_id) | ||
).values(**values) | ||
) | ||
|
||
def after_commit(self, session): | ||
if hasattr(session, '_object_cache'): | ||
del session._object_cache | ||
|
||
def after_rollback(self, session): | ||
if hasattr(session, '_object_cache'): | ||
del session._object_cache | ||
|
||
# __all__ = ['Session', 'engine', 'metadata', 'mapper'] | ||
|
||
# SQLAlchemy database engine. Updated by model.init_model() | ||
engine = None | ||
|
||
Session = orm.scoped_session(orm.sessionmaker( | ||
autoflush=False, | ||
autocommit=False, | ||
expire_on_commit=False, | ||
extension=[CkanCacheExtension(), | ||
CkanSessionExtension(), | ||
extension.PluginSessionExtension(), | ||
activity.DatasetActivitySessionExtension()], | ||
)) | ||
|
||
create_local_session = orm.sessionmaker( | ||
autoflush=False, | ||
autocommit=False, | ||
expire_on_commit=False, | ||
extension=[CkanCacheExtension(), | ||
CkanSessionExtension(), | ||
extension.PluginSessionExtension(), | ||
activity.DatasetActivitySessionExtension()], | ||
) | ||
|
||
#mapper = Session.mapper | ||
mapper = orm.mapper | ||
|
||
# Global metadata. If you have multiple databases with overlapping table | ||
# names, you'll need a metadata for each database | ||
metadata = MetaData() | ||
|
||
|
||
def engine_is_sqlite(sa_engine=None): | ||
# Returns true iff the engine is connected to a sqlite database. | ||
return (sa_engine or engine).url.drivername == 'sqlite' | ||
|
||
|
||
def engine_is_pg(sa_engine=None): | ||
# Returns true iff the engine is connected to a postgresql database. | ||
# According to http://docs.sqlalchemy.org/en/latest/core/engines.html#postgresql | ||
# all Postgres driver names start with `postgres` | ||
return (sa_engine or engine).url.drivername.startswith('postgres') |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
FROM solr:6.2 | ||
FROM solr:6.6.2 | ||
MAINTAINER Open Knowledge | ||
|
||
## Taken from https://github.com/ckan/ckan/blob/ckan-2.7.0/contrib/docker/solr/Dockerfile | ||
# Updated the ARG values | ||
ARG CKAN_VERSION=2.7.6 | ||
ARG CKAN_VERSION=2.8.11 | ||
|
||
# Enviroment | ||
ENV SOLR_CORE ckan | ||
|
||
# User | ||
USER root | ||
|
||
# Create Directories | ||
RUN mkdir -p /opt/solr/server/solr/$SOLR_CORE/conf | ||
RUN mkdir -p /opt/solr/server/solr/$SOLR_CORE/data | ||
|
||
# Adding Files | ||
ADD https://raw.githubusercontent.com/ckan/ckan/ckan-${CKAN_VERSION}/contrib/docker/solr/solrconfig.xml \ | ||
https://raw.githubusercontent.com/ckan/ckan/ckan-${CKAN_VERSION}/ckan/config/solr/schema.xml \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/currency.xml \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/synonyms.txt \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/stopwords.txt \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/basic_configs/conf/protwords.txt \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.0.0/solr/server/solr/configsets/data_driven_schema_configs/conf/elevate.xml \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.6.2/solr/server/solr/configsets/basic_configs/conf/currency.xml \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.6.2/solr/server/solr/configsets/basic_configs/conf/synonyms.txt \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.6.2/solr/server/solr/configsets/basic_configs/conf/stopwords.txt \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.6.2/solr/server/solr/configsets/basic_configs/conf/protwords.txt \ | ||
https://raw.githubusercontent.com/apache/lucene-solr/releases/lucene-solr/6.6.2/solr/server/solr/configsets/data_driven_schema_configs/conf/elevate.xml \ | ||
/opt/solr/server/solr/$SOLR_CORE/conf/ | ||
|
||
# Create Core.properties | ||
RUN echo name=$SOLR_CORE > /opt/solr/server/solr/$SOLR_CORE/core.properties | ||
|
||
# Giving ownership to Solr | ||
USER root | ||
RUN chown -R $SOLR_USER:$SOLR_USER /opt/solr/server/solr/$SOLR_CORE | ||
|
||
# User | ||
USER $SOLR_USER:$SOLR_USER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters