Browse files

Remove old migrations

  • Loading branch information...
1 parent c8b05f4 commit 9bb5d762215b6c218946d68d620397c098b32cc4 @mitechie committed Jun 22, 2012
Showing with 10 additions and 989 deletions.
  1. +10 −0 dbversions/versions/5920b225d05d_load_up_to_date.py
  2. +0 −4 migrations/README
  3. 0 migrations/__init__.py
  4. +0 −3 migrations/manage.py
  5. +0 −20 migrations/migrate.cfg
  6. +0 −27 migrations/versions/001_Initial_bmark_table.py
  7. +0 −31 migrations/versions/002_Add_tags_table.py
  8. +0 −26 migrations/versions/003_Add_date_cols_to_bmarks.py
  9. +0 −97 migrations/versions/004_add_fulltext_table.py
  10. +0 −133 migrations/versions/005_add_url_hash_table.py
  11. +0 −93 migrations/versions/006_add_readable_table.py
  12. +0 −21 migrations/versions/007_add_click_count_to_bmarks.py
  13. +0 −62 migrations/versions/008_Migrate_to_new_hash_algo.py
  14. +0 −30 migrations/versions/009_Add_user_db_table.py
  15. +0 −25 migrations/versions/010_Add_user_to_the_bmark_object.py
  16. +0 −26 migrations/versions/011_api_key_is_user_specific.py
  17. +0 −19 migrations/versions/012_Add_command_tag_for_toread.py
  18. +0 −53 migrations/versions/013_add_name_activation_logger.py
  19. +0 −18 migrations/versions/014_add_signup_date_to_users.py
  20. +0 −17 migrations/versions/015_add_bmark_inserted_by.py
  21. +0 −184 migrations/versions/016_update_fulltext_for_whoosh.py
  22. +0 −28 migrations/versions/017_Rebuild_all_of_the_tag_str_for_bookmarks.py
  23. +0 −23 migrations/versions/018_add_fields_for_the_invite_system.py
  24. +0 −23 migrations/versions/019_add_bookmark_stats.py
  25. +0 −25 migrations/versions/020_add_importer_table_to_track_imports_that_need_to_take_place.py
  26. 0 migrations/versions/__init__.py
  27. +0 −1 requirements.txt
View
10 dbversions/versions/5920b225d05d_load_up_to_date.py
@@ -117,6 +117,14 @@ def upgrade():
sa.Column('completed', sa.DateTime),
sa.PrimaryKeyConstraint('id'),
)
+
+ op.create_table('stats_bookmarks',
+ sa.Column('id', sa.Integer(), nullable=False),
+ sa.Column('tstamp', sa.DateTime),
+ sa.Column('attrib', sa.Unicode(100), nullable=False),
+ sa.Column('data', sa.Integer),
+ sa.PrimaryKeyConstraint('id'),
+ )
### end Alembic commands ###
@@ -130,4 +138,6 @@ def downgrade():
op.drop_table('tags')
op.drop_table('users')
op.drop_table('logging')
+ op.drop_table('import_queue')
+ op.drop_table('stats_bookmarks')
### end Alembic commands ###
View
4 migrations/README
@@ -1,4 +0,0 @@
-This is a database migration repository.
-
-More information at
-http://code.google.com/p/sqlalchemy-migrate/
View
0 migrations/__init__.py
No changes.
View
3 migrations/manage.py
@@ -1,3 +0,0 @@
-#!/usr/bin/env python
-from migrate.versioning.shell import main
-main(debug='False')
View
20 migrations/migrate.cfg
@@ -1,20 +0,0 @@
-[db_settings]
-# Used to identify which repository this database is versioned under.
-# You can use the name of your project.
-repository_id=Bookie
-
-# The name of the database table used to track the schema version.
-# This name shouldn't already be used by your project.
-# If this is changed once a database is under version control, you'll need to
-# change the table name in each database too.
-version_table=migrate_version
-
-# When committing a change script, Migrate will attempt to generate the
-# sql for all supported databases; normally, if one of them fails - probably
-# because you don't have that database installed - it is ignored and the
-# commit continues, perhaps ending successfully.
-# Databases in this list MUST compile successfully during a commit, or the
-# entire commit will fail. List the databases your application will actually
-# be using to ensure your updates to that database work properly.
-# This must be a list; example: ['postgres','sqlite']
-required_dbs=[]
View
27 migrations/versions/001_Initial_bmark_table.py
@@ -1,27 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- """Define the original base bmark table"""
- meta = MetaData(migrate_engine)
-
- b_table = Table('bmarks', meta,
- Column('bid', Integer, autoincrement=True, primary_key=True),
- Column('url', UnicodeText()),
- Column('description', UnicodeText()),
- Column('extended', UnicodeText()),
- # in case this is mysql
- mysql_engine='MyISAM',
- mysql_collate="utf8_general_ci",
- )
-
- b_table.create()
-
-
-def downgrade(migrate_engine):
- """Obviously, drop said table"""
- meta = MetaData(migrate_engine)
-
- b_table = Table('bmarks', meta)
- b_table.drop()
View
31 migrations/versions/002_Add_tags_table.py
@@ -1,31 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- """Add the tags table and the assoc table for bmarks"""
- meta = MetaData(migrate_engine)
-
- t_table = Table('tags', meta,
- Column('tid', Integer, autoincrement=True, primary_key=True),
- Column('name', Unicode(255), unique=True ),
- )
-
- ta_table = Table('bmark_tags', meta,
- Column('bmark_id', Integer, primary_key=True),
- Column('tag_id', Integer, primary_key=True),
- )
-
- t_table.create()
- ta_table.create()
-
-
-def downgrade(migrate_engine):
- """And drop them away"""
- meta = MetaData(migrate_engine)
-
- t_table = Table('tags', meta)
- ta_table = Table('bmark_tags', meta)
-
- t_table.drop()
- ta_table.drop()
View
26 migrations/versions/003_Add_date_cols_to_bmarks.py
@@ -1,26 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- """Store a datetime for when a bookmark is saved and changed"""
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
-
- stored = Column('stored', DateTime)
- updated = Column('updated', DateTime)
-
- create_column(stored, bmarks)
- create_column(updated, bmarks)
-
-
-def downgrade(migrate_engine):
- """And drop the two new columns"""
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
-
- stored = Column('stored', DateTime)
- updated = Column('updated', DateTime)
-
- drop_column(stored, bmarks)
- drop_column(updated, bmarks)
View
97 migrations/versions/004_add_fulltext_table.py
@@ -1,97 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def for_sqlite(engine):
- """Add the table structure for sqlite db"""
- sql = """CREATE VIRTUAL TABLE fulltext USING fts3(bid, description, extended, tag_string);"""
- engine.execute(sql)
-
-
-def drop_sqlite(engine):
- """The downgrade method for sqlite"""
- sql = """DROP TABLE fulltext"""
- engine.execute(sql)
-
-
-def for_mysql(engine):
- """Add the table structure for mysql db"""
- # add the fulltext index
- ft_index = """ALTER TABLE `bmarks`
- ADD FULLTEXT `fulltext`
- (`description` , `extended`, `tag_str`);
- """
- engine.execute(ft_index)
-
-
-def drop_mysql(engine):
- """The downgrade method for mysql"""
- engine.execute("ALTER TABLE bmarks DROP INDEX `fulltext`;")
-
-
-def for_pgsql(engine):
- """Postgres we're going to start with the slowest, but easiest option"""
- idx_sql = [
- "CREATE INDEX desc_ftidx ON bmarks USING gin(to_tsvector('english', description));",
- "CREATE INDEX ext_ftidx ON bmarks USING gin(to_tsvector('english', extended));",
- "CREATE INDEX tag_ftidx ON bmarks USING gin(to_tsvector('english', tag_str));",
- ]
-
- for sql in idx_sql:
- engine.execute(sql)
-
-
-def drop_pgsql(engine):
- """Postgres, drop the indexes in question"""
- engine.execute("ALTER TABLE bmarks DROP INDEX desc_ftidx;")
- engine.execute("ALTER TABLE bmarks DROP INDEX tag_ftidx;")
-
-
-def upgrade(migrate_engine):
- """Right now this is sqlite specific
-
- Eventually we'll need to detect the db type based on the engine and call
- the correct method to add the right table structure.
-
- The idea is to allow searching on the desc, extended, tags (as words)
-
- I would like to do the url as well, but not sure how to tokenize it.
- e.g. engadget would come up with a search for gadget
-
- """
-
- # add the tag_str column for everyone, who cares
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
-
- tag_str = Column('tag_str', UnicodeText())
- tag_str.create(bmarks)
-
- # now do some db specific modifications for how they support fulltext
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- for_sqlite(migrate_engine)
-
- elif 'mysql' in migrate_engine.dialect.driver.lower():
- for_mysql(migrate_engine)
-
- elif 'pg' in migrate_engine.dialect.driver.lower():
- # currently psycopg2
- for_pgsql(migrate_engine)
-
-
-def downgrade(migrate_engine):
- """And destroy the tables created"""
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
- tag_str = Column('tag_str', UnicodeText())
-
- bmarks.drop_column(tag_str)
-
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- drop_sqlite(migrate_engine)
-
- elif 'mysql' in migrate_engine.dialect.driver.lower():
- drop_mysql(migrate_engine)
-
- elif 'pg' in migrate_engine.dialect.driver.lower():
- drop_pgsql(migrate_engine)
View
133 migrations/versions/005_add_url_hash_table.py
@@ -1,133 +0,0 @@
-"""Add url hash table
-
-This feature is meant to store the urls in a seperate table and provide a short
-url hash for them.
-
-This table will also be used to store some metadata about the urls. We want to
-use the hash to provide a redirect service within bookie. During redirection
-we'll keep track of the click and store a popularity counter in the table.
-
-This will allow us to provide a 'popular' view down the road.
-
-When we get multi-user support into play, the hash table will be the single
-place to store urls and will let us grab other people's tags/etc they stored
-with as suggested tags and such.
-
-"""
-
-import shortuuid
-from sqlalchemy import *
-from sqlalchemy import exc
-from migrate import *
-
-
-def get_url_hash(engine):
- """Generate the url hash table"""
- meta = MetaData(engine)
-
- hash_table = Table('url_hash', meta,
- Column('hash_id', Unicode(22), primary_key=True),
- Column('url', UnicodeText()),
- Column('clicks', Integer),
- )
-
- return hash_table
-
-
-def hash_urls(engine, hash_table, bmarks):
- """Get all of the bmarks in the system and hash the urls into url_hash"""
- conn = engine.connect()
- sel_set = select([bmarks.c.url])
- res = conn.execute(sel_set)
-
- if res.rowcount > 0:
- hash_ins = hash_table.insert()
- values = []
- for bmk in res:
- print "Outputting: " + bmk['url']
- new_dat = {'url': bmk['url'],
- 'hash_id': shortuuid.uuid(url=str(bmk['url'])),
- 'clicks': 0}
- values.append(new_dat)
-
- # now we also need to add that hashid to the bmarks table
- conn.execute(bmarks.update().\
- values(hash_id=new_dat['hash_id']).\
- where(bmarks.c.url==new_dat['url']))
-
- # mass insert into the hash table
- conn.execute(hash_ins, values)
-
-
-def restore_urls(engine, hash_table, bmarks):
- """Go through all of the hash values and store the original urls"""
- conn = engine.connect()
-
- sel_set = select([hash_table.c.url, hash_table.c.hash_id])
- res = conn.execute(sel_set)
-
- for hashed in res:
- conn.execute(bmarks.update().\
- values(url=hashed['url']).\
- where(bmarks.c.hash_id==hashed['hash_id']))
-
-
-def upgrade(migrate_engine):
- """Upgrade is a several step process to keep tings together
-
- - First we need to create the new url_hash table
- - Then we need to add a new url_hash field in the bmarks table
- - Next we need to go through and hash the current urls in the system and
- populate the hash table while adding the hash into the bmarks table
- - finally we can drop the url column from the bmarks table
-
- """
- hash_tbl = get_url_hash(migrate_engine)
- hash_tbl.create()
-
- # now add a hash column to the bmarks table
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
- hash_id = Column('hash_id', Unicode(22))
- create_column(hash_id, bmarks)
-
- hash_urls(migrate_engine, hash_tbl, bmarks)
-
- url_col = Column('url', UnicodeText())
- drop_column(url_col, bmarks)
-
-
-def downgrade(migrate_engine):
- """To downgrade we'll need to reverse the steps
-
- - Create the url column on bmarks
- - copy over all of the original url strings from the hash table
- - drop the hash id column on the bmarks table
- - drop the hash table
-
- """
- hash_tbl = get_url_hash(migrate_engine)
-
- # now add a hash column to the bmarks table
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
- url = Column('url', UnicodeText)
-
- try:
- create_column(url, bmarks)
- except exc.OperationalError:
- # we get an eception with sqlite because you can't drop columns
- # so the url column never went away
- # and here we're trying to add it again
- pass
-
- restore_urls(migrate_engine, hash_tbl, bmarks)
-
- # now we can drop the table
- hash_tbl.drop()
-
- # and the tied column
- hash_col = Column('hash_id', Unicode(22))
- drop_column(hash_col, bmarks)
-
-
View
93 migrations/versions/006_add_readable_table.py
@@ -1,93 +0,0 @@
-from datetime import datetime
-from sqlalchemy import *
-from migrate import *
-
-def for_sqlite(engine):
- """Add the table structure for sqlite db"""
- sql = """CREATE VIRTUAL TABLE readable_fts USING fts3(hash_id, content);"""
- engine.execute(sql)
-
-
-def drop_sqlite(engine):
- """The downgrade method for sqlite"""
- sql = """DROP TABLE readable_fts"""
- engine.execute(sql)
-
-
-def for_mysql(engine):
- """Add the table structure for mysql db"""
- # add the fulltext index
- ft_index = """ALTER TABLE `readable`
- ADD FULLTEXT `readable_fts`
- (`content`);
- """
- engine.execute(ft_index)
-
-
-def drop_mysql(engine):
- """The downgrade method for mysql"""
- engine.execute("ALTER TABLE readable DROP INDEX `readable_fts`;")
-
-
-def for_pgsql(engine):
- """Postgres we're going to start with the slowest, but easiest option"""
- idx_sql = [
- "CREATE INDEX content_ftidx ON readable USING gin(to_tsvector('english', content));",
- ]
-
- for sql in idx_sql:
- engine.execute(sql)
-
-
-def drop_pgsql(engine):
- """Postgres, drop the indexes in question"""
- engine.execute("ALTER TABLE readable DROP INDEX content_ftidx;")
-
-
-def get_table(engine):
- """Get the table def"""
-
- meta = MetaData(engine)
- readable = Table('readable', meta,
- Column('hash_id', Unicode(22), primary_key=True),
- Column('content', UnicodeText),
- Column('imported', DateTime, default=datetime.now),
- Column('content_type', Unicode(255)),
- Column('status_code', Integer),
- Column('status_message', Unicode(255)),
- )
-
- return readable
-
-def upgrade(migrate_engine):
- """setup the db for the readable table content"""
- readable = get_table(migrate_engine)
- readable.create()
-
- # now do some db specific modifications for how they support fulltext
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- for_sqlite(migrate_engine)
-
- elif 'mysql' in migrate_engine.dialect.driver.lower():
- for_mysql(migrate_engine)
-
- elif 'pg' in migrate_engine.dialect.driver.lower():
- # currently psycopg2
- for_pgsql(migrate_engine)
-
-
-def downgrade(migrate_engine):
- """And drop the table
-
- """
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- drop_sqlite(migrate_engine)
-
- elif 'mysql' in migrate_engine.dialect.driver.lower():
- drop_mysql(migrate_engine)
-
- elif 'pg' in migrate_engine.dialect.driver.lower():
- drop_pgsql(migrate_engine)
-
- readable = get_table(migrate_engine)
- readable.drop()
View
21 migrations/versions/007_add_click_count_to_bmarks.py
@@ -1,21 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-def upgrade(migrate_engine):
- """Add a clicks counter to the bmark table for that user
-
- will sync with the hashed clicks for overall clicks
-
- """
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
- clicks = Column('clicks', Integer, nullable=False, server_default='0')
- create_column(clicks, bmarks)
-
-def downgrade(migrate_engine):
- """Remove the new column"""
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
-
- click_col = Column('clicks', Integer)
- drop_column(click_col, bmarks)
View
62 migrations/versions/008_Migrate_to_new_hash_algo.py
@@ -1,62 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-import hashlib
-
-
-def generate_hash(url_string):
- m = hashlib.sha256()
- m.update(url_string)
- return m.hexdigest()[:14]
-
-
-def upgrade(migrate_engine):
- """We've changed the algo for hashing and need to update all hash_id
-
- The hash function is copied to this migration in case we need to change it
- later on. We need to loop through each url in url_hash, generate a new
- hash, and then update the matching hashes in:
-
- url_hash
- bmarks
- readable
- -- if sqlite -- readable_fts
- """
- meta = MetaData(migrate_engine)
-
- # get the list of all urls from url_hash table
- url_hash = Table('url_hash', meta, autoload=True)
- bmarks = Table('bmarks', meta, autoload=True)
- readable = Table('readable', meta, autoload=True)
-
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- readable_fts = Table('readable_fts', meta, autoload=True)
- else:
- readable_fts = None
-
- hashes = migrate_engine.execute(select([url_hash]))
-
- for orig in hashes:
- orig_hash = orig['hash_id']
- new_hash = generate_hash(orig['url'])
-
- up_bmarks = bmarks.update().where(bmarks.c.hash_id==orig_hash).values(hash_id=new_hash)
- up_url_hash = url_hash.update().where(url_hash.c.hash_id==orig_hash).values(hash_id=new_hash)
- up_readable = readable.update().where(readable.c.hash_id==orig_hash).values(hash_id=new_hash)
-
- migrate_engine.execute(up_bmarks)
- migrate_engine.execute(up_url_hash)
- migrate_engine.execute(up_readable)
-
- if readable_fts is not None:
- migrate_engine.execute(
- readable_fts.update().\
- where(readable_fts.c.hash_id==orig_hash).\
- values(hash_id=new_hash))
-
-
-def downgrade(migrate_engine):
- """We're not downgrading. It requires adding back the uuid package to be
- able to re-calc the old hash_id. If you need to downgrade you can do it
- manually by basically copying the above and instead of generate_hash you
- use the shortuuid package to generate a hash"""
- pass
View
30 migrations/versions/009_Add_user_db_table.py
@@ -1,30 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-def upgrade(migrate_engine):
- """Add the users table we'll use """
- meta = MetaData(migrate_engine)
- user = Table('users', meta,
- Column('id', Integer, autoincrement=True, primary_key=True),
- Column('username', Unicode(255), unique=True),
- Column('password', Unicode(60)),
- Column('email', Unicode(255), unique=True),
- Column('activated', Boolean, server_default="0"),
- Column('is_admin', Boolean, server_default="0"),
- Column('last_login', DateTime),
- )
-
- user.create()
-
- # adding an initial user account with user/pass combo of admin:admin
- migrate_engine.execute(user.insert().values(username=u'admin',
- password=u'$2a$10$LoSEVbN6833RtwbGQlMhJOROgkjHNH4gjmzkLrIxOX1xLXNvaKFyW',
- email=u'testing@dummy.com',
- activated=True,
- is_admin=True))
-
-def downgrade(migrate_engine):
- """And the big drop"""
- meta = MetaData(migrate_engine)
- user = Table('users', meta)
- user.drop()
View
25 migrations/versions/010_Add_user_to_the_bmark_object.py
@@ -1,25 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-def upgrade(migrate_engine):
- """Add the username field to the bmarks table"""
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
-
- # we can't have nullable at first, we need to set the values
- username = Column('username', Unicode(255))
- create_column(username, bmarks)
-
- # all current bookmarks need to be owned by 'admin' our default user
- migrate_engine.execute(bmarks.update().values(username=u'admin'))
-
- # now we add on the nullable=False
- alter_column('username', nullable=False, table=bmarks)
-
-def downgrade(migrate_engine):
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
- username = Column('username', Unicode(255), nullable=False)
-
- drop_column(username, bmarks)
-
View
26 migrations/versions/011_api_key_is_user_specific.py
@@ -1,26 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-from bookie.models.auth import User
-
-def upgrade(migrate_engine):
- """Need to add a col to the users for their api key"""
- meta = MetaData(migrate_engine)
-
- users = Table('users', meta, autoload=True)
- api_key = Column('api_key', Unicode(12))
- create_column(api_key, users)
-
- # now add an api key for our admin user
- migrate_engine.execute(users.update().\
- where(users.c.username==u'admin').\
- values(api_key=User.gen_api_key()))
-
-
-def downgrade(migrate_engine):
- """And bye bye api key column"""
- meta = MetaData(migrate_engine)
-
- users = Table('users', meta, autoload=True)
- api_key = Column('api_key', Unicode(12))
-
- drop_column(api_key, users)
View
19 migrations/versions/012_Add_command_tag_for_toread.py
@@ -1,19 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-def upgrade(migrate_engine):
- """Need to add a new tag we can use via commands !toread, toread"""
- meta = MetaData(migrate_engine)
-
- tags = Table('tags', meta, autoload=True)
-
- migrate_engine.execute(tags.insert().\
- values(name='toread'))
-
-def downgrade(migrate_engine):
- """And remove that tag"""
- meta = MetaData(migrate_engine)
- tags = Table('tags', meta, autoload=True)
- migrate_engine.execute(tags.delete().\
- where(name='toread'))
-
View
53 migrations/versions/013_add_name_activation_logger.py
@@ -1,53 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- meta = MetaData(migrate_engine)
-
- # add the name column to the user table which we'll put into the account
- # view
- users = Table('users', meta, autoload=True)
- name = Column('name', Unicode(255))
- create_column(name, users)
-
- # add a table for activations, we need to be able to store validation keys
- # with timeouts so that we can reset/activate user accounts
- # is_active would be false and we'd check for a key and if that key is
- # still valid here
- activations = Table('activations', meta,
- Column('id', Integer, primary_key=True),
- Column('code', Unicode(60)),
- Column('valid_until', DateTime),
- Column('created_by', Unicode(255)),
- )
-
- activations.create()
-
- # we also want to start adding some logging information, eventually we'll
- # want this out of the db, but for now, let's log it and we'll work on
- # making this better later
- logging = Table('logging', meta,
- Column('id', Integer, autoincrement=True, primary_key=True),
- Column('user', Unicode(255), nullable=False),
- Column('component', Unicode(50), nullable=False),
- Column('status', Unicode(10), nullable=False),
- Column('message', Unicode(255), nullable=False),
- Column('payload', UnicodeText),
- Column('tstamp', DateTime),
- )
- logging.create()
-
-
-def downgrade(migrate_engine):
- meta = MetaData(migrate_engine)
-
- users = Table('users', meta, autoload=True)
- name = Column('name', Unicode(255))
-
- drop_column(name, users)
-
- activations = Table('activations', meta)
- activations.drop()
- logging = Table('logging', meta)
- logging.drop()
View
18 migrations/versions/014_add_signup_date_to_users.py
@@ -1,18 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- meta = MetaData(migrate_engine)
- users = Table('users', meta, autoload=True)
- signup = Column('signup', DateTime)
- create_column(signup, users)
-
-
-def downgrade(migrate_engine):
- meta = MetaData(migrate_engine)
-
- users = Table('users', meta, autoload=True)
- signup = Column('signup', DateTime)
-
- drop_column(signup, users)
View
17 migrations/versions/015_add_bmark_inserted_by.py
@@ -1,17 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-def upgrade(migrate_engine):
- meta = MetaData(migrate_engine)
- bmarks = Table('bmarks', meta, autoload=True)
- inserted_by = Column('inserted_by', Unicode(255))
- create_column(inserted_by, bmarks)
-
-
-def downgrade(migrate_engine):
- meta = MetaData(migrate_engine)
-
- bmarks = Table('bmarks', meta, autoload=True)
- inserted_by = Column('inserted_by', Unicode(255))
-
- drop_column(inserted_by, bmarks)
View
184 migrations/versions/016_update_fulltext_for_whoosh.py
@@ -1,184 +0,0 @@
-import os
-from BeautifulSoup import BeautifulSoup
-from datetime import datetime
-from sqlalchemy import *
-from sqlalchemy.exc import ProgrammingError
-from migrate import *
-
-from whoosh.fields import SchemaClass, TEXT, KEYWORD, ID
-from whoosh.analysis import StemmingAnalyzer
-from whoosh.index import create_in
-from whoosh.index import open_dir
-
-
-def for_sqlite(engine):
- """Add the table structure for sqlite db"""
- sql = """CREATE VIRTUAL TABLE fulltext USING fts3(bid, description, extended, tag_string);"""
- engine.execute(sql)
-
-
-def drop_sqlite(engine):
- """The downgrade method for sqlite"""
- sql = """DROP TABLE fulltext"""
- engine.execute(sql)
-
-
-def for_mysql(engine):
- """Add the table structure for mysql db"""
- # add the fulltext index
- ft_index = """ALTER TABLE `bmarks`
- ADD FULLTEXT `fulltext`
- (`description` , `extended`, `tag_str`);
- """
- engine.execute(ft_index)
-
-
-def drop_mysql(engine):
- """The downgrade method for mysql"""
- engine.execute("ALTER TABLE bmarks DROP INDEX `fulltext`;")
-
-
-def for_pgsql(engine):
- """Postgres we're going to start with the slowest, but easiest option"""
- idx_sql = [
- "CREATE INDEX desc_ftidx ON bmarks USING gin(to_tsvector('english', description));",
- "CREATE INDEX ext_ftidx ON bmarks USING gin(to_tsvector('english', extended));",
- "CREATE INDEX tag_ftidx ON bmarks USING gin(to_tsvector('english', tag_str));",
- ]
-
- for sql in idx_sql:
- engine.execute(sql)
-
-
-def drop_pgsql(engine):
- """Postgres, drop the indexes in question"""
- try:
- engine.execute("DROP INDEX desc_ftidx;")
- engine.execute("DROP INDEX tag_ftidx;")
- except ProgrammingError:
- # if the indexes are gone oh well
- pass
-
-
-def run_whoosh_index(engine):
- """Build the whoosh index from anything in the db currently"""
- meta = MetaData(engine)
-
- class BmarkSchema(SchemaClass):
- bid = ID(unique=True, stored=True)
- description = TEXT
- extended = TEXT
- tags = KEYWORD
- readable = TEXT(analyzer=StemmingAnalyzer())
-
- INDEX_NAME = 'bookie_index'
- if not os.path.exists(INDEX_NAME):
- os.mkdir(INDEX_NAME)
- WIX = create_in(INDEX_NAME, BmarkSchema)
- else:
- WIX = open_dir(INDEX_NAME)
-
- def get_writer():
- writer = WIX.writer()
- return writer
-
- writer = get_writer()
-
- bmarks = Table('bmarks', meta, autoload=True)
- readable = Table('readable', meta, autoload=True)
-
- bmark_readable = Table('bmark_readable', meta,
- Column('bid', Integer, unique=True, index=True),
- Column('hash_id', Unicode(22), index=True),
- Column('content', UnicodeText),
- Column('clean_content', UnicodeText),
- Column('imported', DateTime, default=datetime.now),
- Column('content_type', Unicode(255)),
- Column('status_code', Integer),
- Column('status_message', Unicode(255)),
- )
-
- bmark_readable.create()
-
- b = select([bmarks])
- r = select([readable])
-
- all_b = engine.execute(b)
- all_r = engine.execute(r)
-
- ord_r = dict([(r['hash_id'], r) for r in all_r])
-
- ins = bmark_readable.insert()
-
- def clean(content):
- return u' '.join(BeautifulSoup(content).findAll(text=True))
-
- for b in all_b:
- if b['hash_id'] in ord_r and ord_r[b['hash_id']]['content'] is not None:
- fulltext = clean(ord_r[b['hash_id']]['content'])
- else:
- fulltext = u""
-
- if b['hash_id'] in ord_r:
- r = ord_r[b['hash_id']]
-
- bmark_r_data = {
- 'bid': b['bid'],
- 'hash_id': b['hash_id'],
- 'content': r['content'],
- 'clean_content': fulltext,
- 'imported': r['imported'],
- 'content_type': r['content_type'],
- 'status_code': r['status_code'],
- 'status_message': r['status_message']
- }
-
- engine.execute(ins, [bmark_r_data])
-
- writer.update_document(
- bid=unicode(b['bid']),
- description=b['description'] if b['description'] else u"",
- extended=b['extended'] if b['extended'] else u"",
- tags=b['tag_str'] if b['tag_str'] else u"",
- readable=fulltext,
- )
-
- writer.commit()
- readable.drop()
-
-
-def upgrade(migrate_engine):
- """Destroy all the fulltext indexes/code since we're moving to whoosh"""
-
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- drop_sqlite(migrate_engine)
-
- elif 'mysql' in migrate_engine.dialect.driver.lower():
- drop_mysql(migrate_engine)
-
- elif 'pg' in migrate_engine.dialect.driver.lower():
- drop_pgsql(migrate_engine)
-
-
- run_whoosh_index(migrate_engine)
-
-
-def downgrade(migrate_engine):
- """ A downgrade means putting the indexes back
-
- The idea is to allow searching on the desc, extended, tags (as words)
-
- I would like to do the url as well, but not sure how to tokenize it.
- e.g. engadget would come up with a search for gadget
-
- """
- # now do some db specific modifications for how they support fulltext
- if 'sqlite' in migrate_engine.dialect.driver.lower():
- for_sqlite(migrate_engine)
-
- elif 'mysql' in migrate_engine.dialect.driver.lower():
- for_mysql(migrate_engine)
-
- elif 'pg' in migrate_engine.dialect.driver.lower():
- # currently psycopg2
- for_pgsql(migrate_engine)
View
28 migrations/versions/017_Rebuild_all_of_the_tag_str_for_bookmarks.py
@@ -1,28 +0,0 @@
-from collections import defaultdict
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- """Walk through all bookmarks and reset the tag_str field"""
- meta = MetaData(migrate_engine)
- engine = migrate_engine
- bmarks = Table('bmarks', meta, autoload=True)
- tags = Table('tags', meta, autoload=True)
- btags = Table('bmark_tags', meta, autoload=True)
-
- b = select([bmarks, btags, tags]).where(bmarks.c.bid==btags.c.bmark_id).\
- where(btags.c.tag_id==tags.c.tid)
- all_b = engine.execute(b)
-
- summary = defaultdict(list)
- for b in all_b:
- summary[b['bid']].append(b['name'])
-
- for key, tags in summary.items():
- engine.execute(bmarks.update().values(tag_str=" ".join(tags)).where(bmarks.c.bid==key))
-
-
-def downgrade(migrate_engine):
- """No valid undo here, so just pass"""
- pass
View
23 migrations/versions/018_add_fields_for_the_invite_system.py
@@ -1,23 +0,0 @@
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- meta = MetaData(migrate_engine)
- user = Table('users', meta, autoload=True)
- invite_ct = Column('invite_ct', Integer, server_default="0")
- invited_by = Column('invited_by', Unicode(255))
-
- create_column(invite_ct, user)
- create_column(invited_by, user)
-
-
-def downgrade(migrate_engine):
- meta = MetaData(migrate_engine)
-
- user = Table('users', meta, autoload=True)
- invite_ct = Column('invite_ct', Integer)
- invited_by = Column('invited_by', Unicode(255))
-
- drop_column(invite_ct, user)
- drop_column(invited_by, user)
View
23 migrations/versions/019_add_bookmark_stats.py
@@ -1,23 +0,0 @@
-from datetime import datetime
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- """Add the stats bookmark table"""
- meta = MetaData(migrate_engine)
-
- stats = Table('stats_bookmarks', meta,
- Column('id', Integer, autoincrement=True, primary_key=True),
- Column('tstamp', DateTime, default=datetime.now),
- Column('attrib', Unicode(100), nullable=False),
- Column('data', Integer, nullable=False, default=0)
- )
- stats.create()
-
-
-def downgrade(migrate_engine):
- """Bye stats bookmark table"""
- meta = MetaData(migrate_engine)
- stats = Table('stats_bookmarks', meta)
- stats.drop()
View
25 migrations/versions/020_add_importer_table_to_track_imports_that_need_to_take_place.py
@@ -1,25 +0,0 @@
-from datetime import datetime
-from sqlalchemy import *
-from migrate import *
-
-
-def upgrade(migrate_engine):
- """Add the importer table"""
- meta = MetaData(migrate_engine)
-
- importer = Table('import_queue', meta,
- Column('id', Integer, autoincrement=True, primary_key=True),
- Column('username', Unicode(255)),
- Column('file_path', Unicode(100), nullable=False),
- Column('tstamp', DateTime, default=datetime.now),
- Column('status', Integer),
- Column('completed', DateTime),
- )
- importer.create()
-
-
-def downgrade(migrate_engine):
- """Bye importer table"""
- meta = MetaData(migrate_engine)
- stats = Table('import_queue', meta)
- stats.drop()
View
0 migrations/versions/__init__.py
No changes.
View
1 requirements.txt
@@ -41,7 +41,6 @@ rope==0.9.3
ropemode==0.1-rc2
ropevim==0.3-rc
requests
-sqlalchemy-migrate<0.8
transaction==1.1.1
translationstring==0.4
unidecode==0.04.7

0 comments on commit 9bb5d76

Please sign in to comment.