aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Pipfile7
-rw-r--r--Pipfile.lock22
-rw-r--r--fatcat/api.py166
-rw-r--r--fatcat/config.py2
-rw-r--r--fatcat/schema.py68
5 files changed, 186 insertions, 79 deletions
diff --git a/Pipfile b/Pipfile
index 876e04a6..be2c1820 100644
--- a/Pipfile
+++ b/Pipfile
@@ -11,5 +11,10 @@ name = "pypi"
[packages]
-sqlalchemy = "1.2"
flask = "*"
+sqlalchemy = "*"
+
+
+[requires]
+
+python_version = "3.5"
diff --git a/Pipfile.lock b/Pipfile.lock
index 62f57613..f161e7cf 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,23 +1,25 @@
{
"_meta": {
"hash": {
- "sha256": "24c6cfcf0485df83f3066606e51aa72a2a4978a7e67f4ae61e2aa59ad78ed982"
+ "sha256": "fe78a27e3e59fb6689a6fe276f556286edf0daf058cd98af7f72b4088660809b"
},
"host-environment-markers": {
"implementation_name": "cpython",
- "implementation_version": "0",
+ "implementation_version": "3.5.3",
"os_name": "posix",
"platform_machine": "x86_64",
"platform_python_implementation": "CPython",
- "platform_release": "4.9.0-4-amd64",
+ "platform_release": "4.9.0-6-amd64",
"platform_system": "Linux",
- "platform_version": "#1 SMP Debian 4.9.51-1 (2017-09-28)",
- "python_full_version": "2.7.13",
- "python_version": "2.7",
- "sys_platform": "linux2"
+ "platform_version": "#1 SMP Debian 4.9.82-1+deb9u2 (2018-02-21)",
+ "python_full_version": "3.5.3",
+ "python_version": "3.5",
+ "sys_platform": "linux"
},
"pipfile-spec": 6,
- "requires": {},
+ "requires": {
+ "python_version": "3.5"
+ },
"sources": [
{
"name": "pypi",
@@ -62,9 +64,9 @@
},
"sqlalchemy": {
"hashes": [
- "sha256:9ede7070d6fd18f28058be88296ed67893e2637465516d6a596cd9afea97b154"
+ "sha256:249000654107a420a40200f1e0b555a79dfd4eff235b2ff60bc77714bd045f2d"
],
- "version": "==1.2.1"
+ "version": "==1.2.5"
},
"werkzeug": {
"hashes": [
diff --git a/fatcat/api.py b/fatcat/api.py
new file mode 100644
index 00000000..6e8f9bdf
--- /dev/null
+++ b/fatcat/api.py
@@ -0,0 +1,166 @@
+
+import argparse
+from flask import Flask, render_template, send_from_directory, request, \
+ url_for, abort, g, redirect, jsonify
+from sqlalchemy import create_engine, MetaData, Table
+
+app = Flask(__name__)
+app.config.from_pyfile('config.py')
+
+metadata = MetaData()
+
+
+## SQL Schema ###############################################################
+
+import enum
+from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey, \
+ Enum
+
+# TODO: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/mixins.html
+
+class IdState(enum.Enum):
+ normal = 1
+ redirect = 2
+ removed = 3
+
+work_id = Table('work_id', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=False),
+ Column('revision', ForeignKey('work_revision.id')),
+ )
+
+work_revision = Table('work_revision', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('previous', ForeignKey('work_revision.id'), nullable=True),
+ Column('state', Enum(IdState)),
+ Column('redirect_id', ForeignKey('work_id.id'), nullable=True),
+ Column('edit_id', ForeignKey('edit.id')),
+
+ Column('title', String),
+ Column('work_type', String),
+ Column('date', String),
+ )
+
+release_id = Table('release_id', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=False),
+ Column('revision', ForeignKey('release_revision.id')),
+ )
+
+release_revision = Table('release_revision', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('previous', ForeignKey('release_revision.id'), nullable=True),
+ Column('state', Enum(IdState)),
+ Column('redirect_id', ForeignKey('release_id.id'), nullable=True),
+ Column('edit_id', ForeignKey('edit.id')),
+
+ Column('work', ForeignKey('work_id.id')),
+ Column('container', ForeignKey('container_id.id')),
+ Column('title', String),
+ Column('license', String), # TODO: oa status foreign key
+ Column('release_type', String), # TODO: foreign key
+ Column('date', String), # TODO: datetime
+ Column('doi', String), # TODO: identifier table
+ )
+
+creator_id = Table('creator_id', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=False),
+ Column('revision', ForeignKey('creator_revision.id')),
+ )
+
+creator_revision = Table('creator_revision', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('previous', ForeignKey('creator_revision.id'), nullable=True),
+ Column('state', Enum(IdState)),
+ Column('redirect_id', ForeignKey('creator_id.id'), nullable=True),
+ Column('edit_id', ForeignKey('edit.id')),
+
+ Column('name', String),
+ Column('sortname', String),
+ Column('orcid', String), # TODO: identifier table
+ )
+
+work_contrib = Table('work_contrib', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('work_rev', ForeignKey('work_revision.id'), nullable=False),
+ Column('creator_id', ForeignKey('creator_id.id'), nullable=False),
+ )
+
+release_contrib = Table('release_contrib', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('release_rev', ForeignKey('release_revision.id'), nullable=False),
+ Column('creator_id', ForeignKey('creator_id.id'), nullable=False),
+ )
+
+container_id = Table('container_id', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=False),
+ Column('revision', ForeignKey('container_revision.id')),
+ )
+
+container_revision = Table('container_revision', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('previous', ForeignKey('container_revision.id'), nullable=True),
+ Column('state', Enum(IdState)),
+ Column('redirect_id', ForeignKey('container_id.id'), nullable=True),
+ Column('edit_id', ForeignKey('edit.id')),
+
+ Column('name', String),
+ Column('container', ForeignKey('container_id.id')),
+ Column('publisher', String), # TODO: foreign key
+ Column('sortname', String),
+ Column('issn', String), # TODO: identifier table
+ )
+
+edit = Table('edit', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('edit_group', ForeignKey('edit_group.id')),
+ Column('editor', ForeignKey('editor.id')),
+ )
+
+edit_group = Table('edit_group', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ )
+
+editor = Table('editor', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('username', String),
+ )
+
+changelog = Table('changelog', metadata,
+ Column('id', Integer, primary_key=True, autoincrement=True),
+ Column('edit_id', ForeignKey('edit.id')),
+ Column('timestamp', Integer),
+ )
+
+
+## API Methods ##############################################################
+
+@app.route('/health', methods=['GET'])
+def health():
+ return jsonify({'ok': True})
+
+## Entry Point ##############################################################
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--debug',
+ action='store_true',
+ help="enable debugging interface")
+ parser.add_argument('--host',
+ default="127.0.0.1",
+ help="listen on this host/IP")
+ parser.add_argument('--port',
+ type=int,
+ default=8040,
+ help="listen on this port")
+ parser.add_argument('--database-uri',
+ default="sqlite:///test.sqlite",
+ help="sqlalchemy database string")
+ args = parser.parse_args()
+
+ app.config['DATABASE_URI'] = args.database_uri
+ engine = create_engine(app.config['DATABASE_URI'], convert_unicode=True)
+ metadata.create_all(bind=engine)
+ app.run(debug=args.debug, host=args.host, port=args.port)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/fatcat/config.py b/fatcat/config.py
new file mode 100644
index 00000000..d4196230
--- /dev/null
+++ b/fatcat/config.py
@@ -0,0 +1,2 @@
+
+DATABASE_URI = "sqlite:///test.sqlite"
diff --git a/fatcat/schema.py b/fatcat/schema.py
deleted file mode 100644
index cdc98ccf..00000000
--- a/fatcat/schema.py
+++ /dev/null
@@ -1,68 +0,0 @@
-
-from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
-
-metadata = MetaData()
-
-# TODO: http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/mixins.html
-
-work_id = Table('work_id', metadata,
- Column('id', Integer, primary_key=True, autoincrement=False),
- Column('revision', ForeignKey('work_revision.id')),
- )
-
-work_revision = Table('work_revision', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- Column('previous', ForeignKey('work_revision.id'), nullable=True),
- Column('state', enum('normal', 'redirect', 'removed')),
- Column('redirect_id', ForeignKey('work_id.id'), nullable=True)),
- Column('edit_id'), ForeignKey('edit.id')),
-
- Column('title', String),
- Column('work_type', ForeignKey()),
- Column('date', String),
- Column('journal', String),
- Column('doi', String),
- )
-
-creator_id = Table('creator_id', metadata,
- Column('id', Integer, primary_key=True, autoincrement=False),
- Column('revision', ForeignKey('creator_revision.id')),
- )
-
-creator_revision = Table('creator_revision', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- Column('previous', ForeignKey('creator_revision.id'), optional=True),
- Column('state', enum('normal', 'redirect', 'removed')),
- Column('redirect_id', ForeignKey('creator_id.id'), optional=True)),
- Column('edit_id'), ForeignKey('edit.id')),
-
- Column('name', String),
- Column('sortname', String),
- )
-
-authorship = Table('authorship', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- Column('work_rev', ForeignKey('work_revision.id'), nullable=False),
- Column('creator_id', ForeignKey('creator_id.id'), nullable=False),
- )
-
-edit = Table('edit', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- Column('edit_group', ForeignKey('edit_group.id')),
- Column('editor', ForeignKey('editor.id')),
- )
-
-edit_group = Table('edit_group', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- )
-
-editor = Table('editor', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- Column('username', String),
- )
-
-changelog = Table('changelog', metadata,
- Column('id', Integer, primary_key=True, autoincrement=True),
- Column('edit_id', ForeignKey('edit.id')),
- Column('timestamp', Integer),
- )