Commits

Marcin Lulek committed d5d1089

change alembic dir name

  • Participants
  • Parent commits 2b5b737

Comments (0)

Files changed (14)

 # A generic, single database configuration.
 
 [alembic]
-script_location = alembic
+script_location = zf_alembic
 sqlalchemy.url = postgresql://test:test@localhost/errormator
 
 

File alembic/README

-Generic single-database configuration.

File alembic/env.py

-from alembic import context
-from sqlalchemy import engine_from_config
-from logging.config import fileConfig
-config = context.config
-
-fileConfig(config.config_file_name)
-
-engine = engine_from_config(
-            config.get_section('alembic'), prefix='sqlalchemy.')
-
-connection = engine.connect()
-context.configure_connection(connection)
-trans = connection.begin()
-try:
-    context.run_migrations()
-    trans.commit()
-except:
-    trans.rollback()
-    raise

File alembic/script.py.mako

-"""${message}
-
-Revision ID: ${up_revision}
-Revises: ${down_revision}
-Create Date: ${create_date}
-
-"""
-
-# downgrade revision identifier, used by Alembic.
-down_revision = ${repr(down_revision)}
-
-from alembic.op import *
-import sqlalchemy as sa
-
-def upgrade():
-    pass
-
-def downgrade():
-    pass

File alembic/versions/24ab8d11f014.py

-"""add external identity tables
-
-Revision ID: 24ab8d11f014
-Revises: 2bb1ba973f0b
-Create Date: 2011-11-10 23:18:19.446844
-
-"""
-
-# downgrade revision identifier, used by Alembic.
-down_revision = '2bb1ba973f0b'
-
-from alembic.op import *
-import sqlalchemy as sa
-
-def upgrade():
-    create_table('external_identities',
-                 sa.Column('external_id', sa.Unicode(255), primary_key=True),
-                 sa.Column('external_user_name', sa.Unicode(50), default=u''),
-                 sa.Column('local_user_name', sa.Unicode(50),
-                           sa.ForeignKey('users.user_name', onupdate='CASCADE',
-                                      ondelete='CASCADE'), primary_key=True),
-                 sa.Column('provider_name', sa.Unicode(50), default=u'',
-                           primary_key=True),
-                 sa.Column('access_token', sa.String(255), default=u''),
-                 sa.Column('alt_token', sa.String(255), default=u''),
-                 sa.Column('token_secret', sa.String(255), default=u'')
-
-                 )
-
-
-def downgrade():
-    drop_table('external_identities')

File alembic/versions/2bb1ba973f0b.py

-"""initial table layout
-
-Revision ID: 2bb1ba973f0b
-Revises: None
-Create Date: 2011-11-10 22:32:14.464939
-
-"""
-
-# downgrade revision identifier, used by Alembic.
-down_revision = None
-
-from alembic.op import *
-import sqlalchemy as sa
-
-def upgrade():
-    create_table('groups',
-                 sa.Column('id', sa.Integer, primary_key=True),
-                 sa.Column('group_name', sa.Unicode(50), unique=True),
-                 sa.Column('description', sa.Text()),
-                 sa.Column('member_count', sa.Integer, nullable=False, default=0)
-                 )
-    create_table('groups_permissions',
-                 sa.Column('group_name', sa.Unicode(50),
-                        sa.ForeignKey('groups.group_name', onupdate='CASCADE',
-                                      ondelete='CASCADE'), primary_key=True),
-                 sa.Column('perm_name', sa.Unicode(30), primary_key=True)
-                 )
-    # TODO
-    # CONSTRAINT groups_permissions_perm_name_check CHECK (perm_name::text = lower(perm_name::text))
-    
-        
-    create_table('users',
-                 sa.Column('id',sa.Integer, primary_key=True),
-                 sa.Column('user_name',sa.Unicode(30), unique=True),
-                 sa.Column('user_password',sa.String(40)),
-                 sa.Column('email',sa.Unicode(100), nullable=False, unique=True),
-                 sa.Column('status',sa.SmallInteger(), nullable=False),
-                 sa.Column('security_code',sa.String(40), default='default'),
-                 sa.Column('last_login_date',sa.TIMESTAMP(timezone=True),
-                                default=sa.sql.func.now(),
-                                server_default=sa.func.now()
-                                )
-                 )
-    # TODO for postgresql
-#CREATE UNIQUE INDEX users_email_key
-#  ON users
-#  USING btree
-#  (lower(email::text));
-#
-#-- Index: users_username_uq
-#
-#-- DROP INDEX users_username_uq;
-#
-#CREATE INDEX users_username_uq
-#  ON users
-#  USING btree
-#  (lower(user_name::text));
-
-    
-    create_table('users_permissions',
-                 sa.Column('user_name', sa.Unicode(50),
-                         sa.ForeignKey('users.user_name', onupdate='CASCADE',
-                                       ondelete='CASCADE'), primary_key=True),
-                 sa.Column('perm_name', sa.Unicode(30), primary_key=True)
-                 )
-    
-    create_table('users_groups',
-                 sa.Column('group_name', sa.Unicode(50),
-                         sa.ForeignKey('groups.group_name', onupdate='CASCADE',
-                                       ondelete='CASCADE'), primary_key=True),
-                 sa.Column('user_name', sa.Unicode(30),
-                        sa.ForeignKey('users.user_name', onupdate='CASCADE',
-                                      ondelete='CASCADE'), primary_key=True)
-                 )
-
-    create_table('resources',
-                 sa.Column('resource_id', sa.BigInteger(), primary_key=True, nullable=False),
-                 sa.Column('resource_name', sa.Unicode(100), nullable=False),
-                 sa.Column('resource_type', sa.Unicode(30), nullable=False),
-                 sa.Column('owner_group_name',sa.Unicode(50),
-                       sa.ForeignKey('groups.group_name', onupdate='CASCADE',
-                                     ondelete='SET NULL')),
-                 sa.Column('owner_user_name',sa.Unicode(30),
-                       sa.ForeignKey('users.user_name', onupdate='CASCADE',
-                                     ondelete='SET NULL'))
-                 )
-
-    create_table('groups_resources_permissions',
-                 sa.Column('group_name', sa.Unicode(50), sa.ForeignKey('groups.group_name',
-                                                     onupdate='CASCADE',
-                                                     ondelete='CASCADE'),
-                                                     primary_key=True),
-                 sa.Column('resource_id', sa.BigInteger(), sa.ForeignKey('resources.resource_id',
-                                                     onupdate='CASCADE',
-                                                     ondelete='CASCADE'),
-                                                     primary_key=True,
-                                                     autoincrement=False),
-                 sa.Column('perm_name', sa.Unicode(50), primary_key=True)
-                 )
-    # TODO for postgresql
-    # CONSTRAINT groups_resources_permissions_perm_name_check CHECK (perm_name::text = lower(perm_name::text))
-    
-    
-    create_table('users_resources_permissions',
-                 sa.Column('user_name', sa.Unicode(50), sa.ForeignKey('users.user_name',
-                                                     onupdate='CASCADE',
-                                                     ondelete='CASCADE'),
-                                                     primary_key=True),
-                 sa.Column('resource_id', sa.BigInteger(), sa.ForeignKey('resources.resource_id',
-                                                     onupdate='CASCADE',
-                                                     ondelete='CASCADE'),
-                                                     primary_key=True,
-                                                     autoincrement=False),
-                 sa.Column('perm_name', sa.Unicode(50), primary_key=True)
-                 )
-    
-    # TODO for postgresql
-    #CONSTRAINT users_resources_permissions_perm_name_check CHECK (perm_name::text = lower(perm_name::text))
-
-def downgrade():
-    # Operations to reverse the above upgrade go here.
-    drop_table('users_resources_permissions')
-    drop_table('groups_resources_permissions')
-    drop_table('resources')
-    drop_table('users_groups')
-    drop_table('users_permissions')
-    drop_table('users')
-    drop_table('groups_permissions')
-    drop_table('groups')

File alembic/versions/5c84d7260c5.py

-"""add id/parent id to resource structure
-
-Revision ID: 5c84d7260c5
-Revises: 24ab8d11f014
-Create Date: 2011-11-11 00:09:09.624704
-
-"""
-
-# downgrade revision identifier, used by Alembic.
-down_revision = '24ab8d11f014'
-
-from alembic.op import *
-import sqlalchemy as sa
-
-def upgrade():
-    add_column('resources', sa.Column('parent_id',sa.BigInteger(),
-        sa.ForeignKey('resources.resource_id',
-                      onupdate='CASCADE', ondelete='SET NULL')))
-
-def downgrade():
-    drop_column('resources','parent_id')

File zf_alembic/README

+Generic single-database configuration.

File zf_alembic/env.py

+from alembic import context
+from sqlalchemy import engine_from_config
+from logging.config import fileConfig
+config = context.config
+
+fileConfig(config.config_file_name)
+
+engine = engine_from_config(
+            config.get_section('alembic'), prefix='sqlalchemy.')
+
+connection = engine.connect()
+context.configure_connection(connection)
+trans = connection.begin()
+try:
+    context.run_migrations()
+    trans.commit()
+except:
+    trans.rollback()
+    raise

File zf_alembic/script.py.mako

+"""${message}
+
+Revision ID: ${up_revision}
+Revises: ${down_revision}
+Create Date: ${create_date}
+
+"""
+
+# downgrade revision identifier, used by Alembic.
+down_revision = ${repr(down_revision)}
+
+from alembic.op import *
+import sqlalchemy as sa
+
+def upgrade():
+    pass
+
+def downgrade():
+    pass

File zf_alembic/versions/24ab8d11f014.py

+"""add external identity tables
+
+Revision ID: 24ab8d11f014
+Revises: 2bb1ba973f0b
+Create Date: 2011-11-10 23:18:19.446844
+
+"""
+
+# downgrade revision identifier, used by Alembic.
+down_revision = '2bb1ba973f0b'
+
+from alembic.op import *
+import sqlalchemy as sa
+
+def upgrade():
+    create_table('external_identities',
+                 sa.Column('external_id', sa.Unicode(255), primary_key=True),
+                 sa.Column('external_user_name', sa.Unicode(50), default=u''),
+                 sa.Column('local_user_name', sa.Unicode(50),
+                           sa.ForeignKey('users.user_name', onupdate='CASCADE',
+                                      ondelete='CASCADE'), primary_key=True),
+                 sa.Column('provider_name', sa.Unicode(50), default=u'',
+                           primary_key=True),
+                 sa.Column('access_token', sa.String(255), default=u''),
+                 sa.Column('alt_token', sa.String(255), default=u''),
+                 sa.Column('token_secret', sa.String(255), default=u'')
+                 )
+
+
+def downgrade():
+    drop_table('external_identities')

File zf_alembic/versions/2bb1ba973f0b.py

+"""initial table layout
+
+Revision ID: 2bb1ba973f0b
+Revises: None
+Create Date: 2011-11-10 22:32:14.464939
+
+"""
+
+# downgrade revision identifier, used by Alembic.
+down_revision = None
+
+from alembic.op import *
+import sqlalchemy as sa
+
+def upgrade():
+    create_table('groups',
+                 sa.Column('id', sa.Integer, primary_key=True),
+                 sa.Column('group_name', sa.Unicode(50), unique=True),
+                 sa.Column('description', sa.Text()),
+                 sa.Column('member_count', sa.Integer, nullable=False, default=0)
+                 )
+    create_table('groups_permissions',
+                 sa.Column('group_name', sa.Unicode(50),
+                        sa.ForeignKey('groups.group_name', onupdate='CASCADE',
+                                      ondelete='CASCADE'), primary_key=True),
+                 sa.Column('perm_name', sa.Unicode(30), primary_key=True)
+                 )
+    # TODO
+    # CONSTRAINT groups_permissions_perm_name_check CHECK (perm_name::text = lower(perm_name::text))
+    
+        
+    create_table('users',
+                 sa.Column('id',sa.Integer, primary_key=True),
+                 sa.Column('user_name',sa.Unicode(30), unique=True),
+                 sa.Column('user_password',sa.String(40)),
+                 sa.Column('email',sa.Unicode(100), nullable=False, unique=True),
+                 sa.Column('status',sa.SmallInteger(), nullable=False),
+                 sa.Column('security_code',sa.String(40), default='default'),
+                 sa.Column('last_login_date',sa.TIMESTAMP(timezone=True),
+                                default=sa.sql.func.now(),
+                                server_default=sa.func.now()
+                                )
+                 )
+    # TODO for postgresql
+#CREATE UNIQUE INDEX users_email_key
+#  ON users
+#  USING btree
+#  (lower(email::text));
+#
+#-- Index: users_username_uq
+#
+#-- DROP INDEX users_username_uq;
+#
+#CREATE INDEX users_username_uq
+#  ON users
+#  USING btree
+#  (lower(user_name::text));
+
+    
+    create_table('users_permissions',
+                 sa.Column('user_name', sa.Unicode(50),
+                         sa.ForeignKey('users.user_name', onupdate='CASCADE',
+                                       ondelete='CASCADE'), primary_key=True),
+                 sa.Column('perm_name', sa.Unicode(30), primary_key=True)
+                 )
+    
+    create_table('users_groups',
+                 sa.Column('group_name', sa.Unicode(50),
+                         sa.ForeignKey('groups.group_name', onupdate='CASCADE',
+                                       ondelete='CASCADE'), primary_key=True),
+                 sa.Column('user_name', sa.Unicode(30),
+                        sa.ForeignKey('users.user_name', onupdate='CASCADE',
+                                      ondelete='CASCADE'), primary_key=True)
+                 )
+
+    create_table('resources',
+                 sa.Column('resource_id', sa.BigInteger(), primary_key=True, nullable=False),
+                 sa.Column('resource_name', sa.Unicode(100), nullable=False),
+                 sa.Column('resource_type', sa.Unicode(30), nullable=False),
+                 sa.Column('owner_group_name',sa.Unicode(50),
+                       sa.ForeignKey('groups.group_name', onupdate='CASCADE',
+                                     ondelete='SET NULL')),
+                 sa.Column('owner_user_name',sa.Unicode(30),
+                       sa.ForeignKey('users.user_name', onupdate='CASCADE',
+                                     ondelete='SET NULL'))
+                 )
+
+    create_table('groups_resources_permissions',
+                 sa.Column('group_name', sa.Unicode(50), sa.ForeignKey('groups.group_name',
+                                                     onupdate='CASCADE',
+                                                     ondelete='CASCADE'),
+                                                     primary_key=True),
+                 sa.Column('resource_id', sa.BigInteger(), sa.ForeignKey('resources.resource_id',
+                                                     onupdate='CASCADE',
+                                                     ondelete='CASCADE'),
+                                                     primary_key=True,
+                                                     autoincrement=False),
+                 sa.Column('perm_name', sa.Unicode(50), primary_key=True)
+                 )
+    # TODO for postgresql
+    # CONSTRAINT groups_resources_permissions_perm_name_check CHECK (perm_name::text = lower(perm_name::text))
+    
+    
+    create_table('users_resources_permissions',
+                 sa.Column('user_name', sa.Unicode(50), sa.ForeignKey('users.user_name',
+                                                     onupdate='CASCADE',
+                                                     ondelete='CASCADE'),
+                                                     primary_key=True),
+                 sa.Column('resource_id', sa.BigInteger(), sa.ForeignKey('resources.resource_id',
+                                                     onupdate='CASCADE',
+                                                     ondelete='CASCADE'),
+                                                     primary_key=True,
+                                                     autoincrement=False),
+                 sa.Column('perm_name', sa.Unicode(50), primary_key=True)
+                 )
+    
+    # TODO for postgresql
+    #CONSTRAINT users_resources_permissions_perm_name_check CHECK (perm_name::text = lower(perm_name::text))
+
+def downgrade():
+    # Operations to reverse the above upgrade go here.
+    drop_table('users_resources_permissions')
+    drop_table('groups_resources_permissions')
+    drop_table('resources')
+    drop_table('users_groups')
+    drop_table('users_permissions')
+    drop_table('users')
+    drop_table('groups_permissions')
+    drop_table('groups')

File zf_alembic/versions/5c84d7260c5.py

+"""add id/parent id to resource structure
+
+Revision ID: 5c84d7260c5
+Revises: 24ab8d11f014
+Create Date: 2011-11-11 00:09:09.624704
+
+"""
+
+# downgrade revision identifier, used by Alembic.
+down_revision = '24ab8d11f014'
+
+from alembic.op import *
+import sqlalchemy as sa
+
+def upgrade():
+    add_column('resources', sa.Column('parent_id',sa.BigInteger(),
+        sa.ForeignKey('resources.resource_id',
+                      onupdate='CASCADE', ondelete='SET NULL')))
+
+def downgrade():
+    drop_column('resources','parent_id')

File ziggurat_foundations/models.py

                         backref='owner'
                         )
 
+    @declared_attr
+    def external_identities(cls):
+        """ returns all external identities for this user"""
+        return sa.orm.relationship('ExternalIdentity',
+                        lazy='dynamic',
+                        cascade="all, delete-orphan",
+                        passive_deletes=True,
+                        passive_updates=True,
+                        backref='owner'
+                        )
+
     @property
     def permissions(self):
         """ returns all non-resource permissions based on what groups user
             return True
         return q.first()
 
+    @classmethod
+    def by_external_identity(cls, provider, username):
+        pass
+
+
 class ExternalIdentityMixin(BaseModel):
 
     @declared_attr
 
     @declared_attr
     def external_id(cls):
-        return sa.Column(sa.Unicode(255), default=u'')
+        return sa.Column(sa.Unicode(255), default=u'', primary_key=True)
 
     @declared_attr
     def external_user_name(cls):
 
     @declared_attr
     def local_user_name(cls):
-        return sa.Column(sa.Unicode(50), default=u'')
+        return sa.Column(sa.Unicode(50), sa.ForeignKey('users.user_name',
+                        onupdate='CASCADE', ondelete='CASCADE'), primary_key=True)
 
     @declared_attr
     def provider_name(cls):
-        return sa.Column(sa.Unicode(50), default=u'')
+        return sa.Column(sa.Unicode(50), default=u'', primary_key=True)
 
     @declared_attr
     def access_token(cls):