337 Commits

Author SHA1 Message Date
Elrond
729424befd Fix media display for no media_data row in sql.
If there is no media_data row for the current media (for
whatever reason, there might be good ones), let
MediaEntry.media_data not raise an exception but just
return None.

The exif display part now handles this by checking whether
.media_data.exif is defined (None has no attribute exif, so
it's undefined, all fine).
2012-03-15 12:35:58 +01:00
Christopher Allan Webber
007ac2e720 Implemented the MediaEntry .media_data type fields for SQL 2012-03-14 18:28:06 -05:00
Elrond
28306810c5 Convert (gps) image media_data.
Add mongo_to_sql convert part for converting the media_data
for images. This currently drops the exif data and thus
only converts gps data.
2012-03-14 21:17:07 +01:00
Elrond
ca722c3caf Migration to move gps data around
Move media_data["gps"]["*"] to media_data["gps_*"].
In preparation for media_data.gps_*
2012-03-14 20:17:49 +01:00
Christopher Allan Webber
4a86335157 Fix VideoData insertion 2012-03-14 14:03:49 -05:00
Elrond
ef7de98ad5 Convert media_data for video
This creates fresh VideoData rows for all the videos in the
mongodb.
2012-03-13 23:08:34 +01:00
Elrond
193e0f5346 Improve logging of sql queries a bit.
Docs:
  http://docs.sqlalchemy.org/en/latest/core/engines.html#configuring-logging

So for an application utilizing python logging for real
(and MediaGoblin should) the rule is:
- Don't use echo=True,
- but reconfigure the appropiate loggers' level.

So replaced the echo=True by a line to reconfigure the
appropiate logger to achieve the same effect.

This still dumps whole bloats of SQL queries into the main
log, but at least they're not duped any more.
2012-03-10 22:48:24 +01:00
Elrond
3c7d451c71 Forgot to add FileKeynames to MODELS 2012-03-08 21:18:17 +01:00
Elrond
a9dac7c83d Normalize MediaFile.name (make it a foreignkey)
The name part of a MediaFile is only using a very limited
number of items. Currently things like "original" or
"thumb".

So instead of storing the string on each entry, just store
a short integer referencing the FileKeynames table and have
the appropiate string there.
2012-03-08 21:11:18 +01:00
Joar Wandborg
4dbf16be33 SQL: Added MediaFile and MediaAttachmentFile to MODELS 2012-03-08 01:02:06 +01:00
Elrond
814334f6eb Generic generate_slug for mongo and sql.
Using the new check_media_slug_used it is possible to have
one generic generate_slug in the mixin class instead of in
each db class.

In the sql variant self.id is not always set: If the slug
alone would create a dupe the current code decides for "no
slug at all".
2012-03-07 21:32:20 +01:00
Elrond
b62b3b982a Generic check_media_slug_used db utility.
In two cases (generating a new slug and editing the slug)
it is nice to know in advance (before the db gets angry)
that the slug is used/free. So created a db utility
function to check for this on mongo and sql:
check_media_slug_used()
2012-03-05 21:37:05 +01:00
Elrond
c65cbf9514 SQL: Tool to cleanup unused tag slugs.
The current SQL layout/sqlalchemy strucuture can't detect
whether a slug isn't needed any more and delete it. So
provide a tool function to cleanup unused slugs.

It's currently not hooked to any gmg function!
2012-03-05 21:30:39 +01:00
Elrond
325ca444d1 Implement atomic_update for SQL.
On sqlalchemy most updates are atomic enough for most use
cases. Anyway, here is an atomic_update that is compatible
to the mongo version.
2012-03-04 21:05:06 +01:00
Elrond
82cd968347 Create atomic_update db utility function
In some cases (notably the mark_entry_failed function) it
is useful to have atomic update functionality on the db. On
mongo this requires special syntax.

So created an atomic_update function for mongo and started
to use it in mark_entry_failed.
2012-03-04 20:58:19 +01:00
Elrond
acb2194919 And media_data_init() for sql as a dummy
Needs to be implemented.
2012-03-03 21:12:57 +01:00
Elrond
5fe1fd0722 Create a fake MediaEntry.media_data for sql
So that the SQL backend is more useable, let the MediaEntry
have a faked media_data.
It's extremely fake: The returned dict is always a new one.
So any stored info is even lost!
2012-03-03 00:16:44 +01:00
Elrond
5ff575827b Video media_data: Change layout in the mongo world
Change the media_data for video from
entry.media_data["video"] to use entry.media_data directly.

Also start a bare MediaEntry.media_data_init(**kwargs)
method for setting up the media_data and possibly
initialising it with kwargs.
2012-03-01 22:25:41 +01:00
Elrond
94df840b3b SQL: Improve video media_data table
1. Make the foreignkey the primary_key.
2. Add width/height, as those are currently in use for the
   media_data
2012-03-01 21:58:49 +01:00
Elrond
2bc8ff0d63 Cleanup Session after each request.
It's good practice to cleanup the SQL session after each
request so that the next request gets a fresh one.

It's an application decision whether one wants a
just-in-case ROLLBACK or COMMIT. There are two ideas behind
it, really. I have decided for ROLLBACK. The idea is "if
you forget to commit your changes yourself, there's
something broken. Maybe you got an exception?".
2012-02-28 20:52:35 +01:00
Elrond
3502958113 Attachment support in the SQL backend
attachments working with the sql backend.

- SQL Schema for attachment files, ordering attachments by
  their name, not by the submission order (as earlier).
- Dot-Notation for attachments, where missing.
- convert existing attachments over from mongo -> sql
2012-02-28 20:52:35 +01:00
Elrond
c60bbe07c5 Let SQL objects support .setdefault() and .delete()
Some parts in the code like to use .setdefault(). So make
them happy and provide a minimal version. It ignores the
given default and expects the attribute to already exist.

Other parts use .delete() to delete a complete object. This
version expects the object to live in a session and also
does the final commit.
2012-02-26 19:46:44 +01:00
Elrond
58f96a13e4 Allow .id instead of ._id for the Mongo backend
To allow easier migration to the SQLAlchemy style .id give
the User and MediaEntry mongo classes an alias attribute of
.id that maps to ['_id'].

Use it in the upload process, because this was one of the
last positions with a ['_id'] instead of ._id (due to a bug
in mongokit).
2012-02-25 14:10:57 +01:00
Elrond
9891351256 Create "gmg convert_mongo_to_sql" command
Finally, to make testing of sql a bit easier, create a
bin/gmg command to do the conversion from mongo to sql.
It's currently named "convert_mongo_to_sql".

The most important option is the gmg -cf option to give a
configfile with the appropiate sql_engine definition.
2012-02-23 23:49:09 +01:00
Elrond
1582181701 mongo to sql convert: Better Ordering
Order the conversion by the "created" attribute. That way
the sql ids are mostly in the order they would have been,
if sql was used earlier.

Makes things nicer to look at in a db dump.
2012-02-23 23:44:13 +01:00
Christopher Allan Webber
3ea1cf36fc Updates so that dbupdate command works
- Various fixes to dbupdate itself
 - Switching db/sql/migrations.py to use a dict instead of a list
 - Registering the function
2012-02-18 23:19:09 -06:00
Christopher Allan Webber
4d8be4fe0d Merge branch 'master' into sqlmigrate 2012-02-18 15:33:29 -06:00
Elrond
a45631e3f3 Start having useful defaults for SQL
Mostly this means: Havintg a config_spec.ini that has a
local (relative to mediagoblin.ini) sqlite db with the name
"mediagoblin.db".

Also:
- Add to .gitignore
- Add a notice to mediagoblin.ini about the db
2012-02-18 19:34:11 +01:00
Elrond
6456cefa0d Fix MediaTag __init__ to handle no args
Let the init code also handle createing a fresh clean
instance without any attrs set.
2012-02-18 19:34:11 +01:00
Elrond
cf27accc9e SQL: fail_metadata as JSON encoded field
fail_metadata used to be a dict in mongo. So a json encoded
field should be okay too.

We could use a pickled field instead, which would be more
flexible.
2012-02-18 19:29:01 +01:00
Christopher Allan Webber
63352aaf70 Merge branch 'master' into sqlmigrate
Conflicts:
	mediagoblin/db/sql/models.py
2012-02-18 10:01:47 -06:00
Elrond
feba5c5287 Drop pre-rendered html: MediaComment.content_html
After a bit of discussion, we decided to drop the
pre-rendered html from the database and render it on
the fly.

In another step, we will use some proper caching method to
cache this stuff.

This commit affects the MediaComment.content_html part.
2012-02-18 12:50:30 +01:00
Elrond
1e72e075f8 Drop pre-rendered html: MediaEntry.description_html
After a bit of discussion, we decided to drop the
pre-rendered html from the database and render it on
the fly.

In another step, we will use some proper caching method to
cache this stuff.

This commit affects the MediaEntry.description_html part.
2012-02-18 12:41:25 +01:00
Elrond
e61ab0998b Drop pre-rendered html: User.bio_html
After a bit of discussion, we decided to drop the
pre-rendered html from the database and render it on
the fly.

In another step, we will use some proper caching method to
cache this stuff.

This commit affects the User.bio_html part.
2012-02-18 12:35:30 +01:00
Elrond
eea6d276bc sql db design suggestions by Svavar Kjarrval
Many thanks go to Svavar Kjarrval who has taken a deeper
look at our current sql db design and made a bunch of
suggestions.  The suggestions are currently put as TODO
items in the docstrings.  This way we can keep track of
them directly where we need it.
2012-02-11 12:11:51 +01:00
Will Kahn-Greene
7f4ebeed76 Fix copyright statements; add LICENSE for EXIF.py 2012-02-08 10:47:08 -05:00
Christopher Allan Webber
cf29e8a824 It's 2012 all up in here 2012-02-02 09:44:13 -06:00
Christopher Allan Webber
78d17b8055 Excepting that migration 1 doesn't work(!), sqlalchemy migration branch working
The reason migration 1 doesn't work, and is commented out, is because
of sqlalchemy-migrate not handling certain constraints while dropping
binary sqlite columns right.  See also:
http://code.google.com/p/sqlalchemy-migrate/issues/detail?id=143&thanks=143&ts=1327882242
2012-01-29 22:19:03 -06:00
Christopher Allan Webber
adf5436373 Update the string outputs to match our tests: newlines, ...->:, etc. 2012-01-29 21:45:05 -06:00
Christopher Allan Webber
bff7098a6c migrations_to_run here a list, so no reason to call it 2012-01-29 17:26:23 -06:00
Christopher Allan Webber
9303d47df0 self.latest_migration now a property, so we shouldn't __call__ it! 2012-01-29 17:08:38 -06:00
Christopher Allan Webber
f98be6a65b For clarity, self.database -> self.session.
Actually, I'm not even sure *that* is ideal!  But better than what we
had...
2012-01-29 17:07:47 -06:00
Christopher Allan Webber
ef8591fdd0 Yet *another* self.database -> self.database.bind fix! 2012-01-29 17:06:19 -06:00
Christopher Allan Webber
396f39c3e9 Fix database_current_version for when self.migration_data is None. 2012-01-29 17:05:16 -06:00
Christopher Allan Webber
16d4dce9e9 another db -> db.bind fix. 2012-01-29 17:00:39 -06:00
Christopher Allan Webber
f3791a9490 A few basic fixes to sql/util.py
- MigrationRecord to MigrationData, again
 - If the table doesn't exist, return None for database_current_migration
 - database.engine -> database.bind
2012-01-29 16:58:58 -06:00
Christopher Allan Webber
e8ba2223fa Also switch database_current_migration to a property 2012-01-29 16:40:46 -06:00
Christopher Allan Webber
47616ece50 Make latest_migration a property 2012-01-29 16:36:33 -06:00
Christopher Allan Webber
9a18573190 Import MigrationData, not MigrationRecord 2012-01-29 16:33:47 -06:00
Christopher Allan Webber
780fdd7bd6 import changeset into sql models 2012-01-29 16:33:46 -06:00