Skip to content

Commit

Permalink
SYS-547 minor schema fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
instantlinux committed Oct 6, 2021
1 parent 553a38b commit 013ca3a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion apicrud/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.2.2'
__version__ = '0.2.3'
vcs_ref = 'unset'
build_date = 'unset'
51 changes: 28 additions & 23 deletions apicrud/alembic/versions/cac2000912a5_initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,6 @@ def upgrade():
batch_op.create_index(batch_op.f('ix_listmembers_list_id'), ['list_id'], unique=False)
batch_op.create_unique_constraint('uniq_listmember', ['list_id', 'uid'])

op.create_table('scopes',
sa.Column('id', sa.String(length=16), nullable=False),
sa.Column('name', sa.String(length=32), nullable=False),
sa.Column('settings_id', sa.String(length=16), nullable=False),
sa.Column('created', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('modified', sa.TIMESTAMP(), nullable=True),
sa.Column('status', sa.Enum('active', 'disabled'), server_default='active',
nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('id'),
sa.UniqueConstraint('name', 'settings_id', name='uniq_scope_name'),
)
op.create_table('apikeyscopes',
sa.Column('apikey_id', sa.String(length=16), primary_key=True, nullable=False),
sa.Column('scope_id', sa.String(length=16), primary_key=True, nullable=False),
sa.Column('created', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['apikey_id'], ['apikeys.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['scope_id'], ['scopes.id'], ondelete='CASCADE'),
)
with op.batch_alter_table('apikeyscopes', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_apikey_scope_id'), ['apikey_id'], unique=False)
batch_op.create_unique_constraint('uniq_apikeyscope', ['apikey_id', 'scope_id'])

op.create_table('settings',
sa.Column('id', sa.String(length=16), nullable=False),
sa.Column('name', sa.String(length=32), nullable=False),
Expand Down Expand Up @@ -256,6 +233,30 @@ def upgrade():
sa.UniqueConstraint('uid')
)

op.create_table('scopes',
sa.Column('id', sa.String(length=16), nullable=False),
sa.Column('name', sa.String(length=32), nullable=False),
sa.Column('settings_id', sa.String(length=16), nullable=False),
sa.Column('created', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('modified', sa.TIMESTAMP(), nullable=True),
sa.Column('status', sa.Enum('active', 'disabled'), server_default='active',
nullable=False),
sa.ForeignKeyConstraint(['settings_id'], ['settings.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('id'),
sa.UniqueConstraint('name', 'settings_id', name='uniq_scope_name'),
)
op.create_table('apikeyscopes',
sa.Column('apikey_id', sa.String(length=16), primary_key=True, nullable=False),
sa.Column('scope_id', sa.String(length=16), primary_key=True, nullable=False),
sa.Column('created', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.ForeignKeyConstraint(['apikey_id'], ['apikeys.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['scope_id'], ['scopes.id'], ondelete='CASCADE'),
)
with op.batch_alter_table('apikeyscopes', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_apikey_scope_id'), ['apikey_id'], unique=False)
batch_op.create_unique_constraint('uniq_apikeyscope', ['apikey_id', 'scope_id'])

op.create_table(
'credentials',
sa.Column('id', sa.String(length=16), primary_key=True, nullable=False),
Expand Down Expand Up @@ -310,4 +311,8 @@ def upgrade():
batch_op.add_column(sa.Column('default_storage_id', sa.String(length=16), nullable=True))
batch_op.create_foreign_key('settings_fk2', 'storageitems', ['default_storage_id'], ['id'])

"""
with op.batch_alter_table('scopes', schema=None) as batch_op:
batch_op.create_foreign_key('scopes_fk2', 'settings', ['settings_id'], ['id'])
"""
# ### end Alembic commands ###
10 changes: 6 additions & 4 deletions apicrud/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,21 @@ def seed_new_db(db_session):
Args:
db_session (obj): existing db session
"""

config = ServiceConfig().config
models = ServiceConfig().models
if not config.DB_SEED_ENABLE:
return
with open(config.DB_SEED_FILE, 'rt', encoding='utf8') as f:
records = yaml.safe_load(f)
if db_session.bind.dialect.name == 'sqlite':
cmd = 'pragma foreign_keys'
else:
cmd = 'SET FOREIGN_KEY_CHECKS'
db_session.execute('%s=off' % cmd)
with open(ServiceConfig().config.DB_SEED_FILE, 'rt', encoding='utf8') as f:
records = yaml.safe_load(f)
if 'tz' not in records:
with open(os.path.join(os.path.dirname(
__file__), 'timezones.yaml'), 'rt', encoding='utf8') as f:
records['tz'] = yaml.safe_load(f)['tz']
models = ServiceConfig().models
for resource, records in records.items():
if resource == '_constants':
continue
Expand Down
6 changes: 5 additions & 1 deletion apicrud/service_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,15 @@ components:
items:
maxLength: 24
type: string
db_seed_enable:
default: true
description: The application provides an initial seed database
type: boolean
db_seed_file:
default: db_seed.yaml
description: >
Name of a file containing records for seeding a new database
file, relative to the openapi_file's parent directory
file, relative to the application's installation directory
type: string
debug:
default: false
Expand Down
15 changes: 2 additions & 13 deletions example/Makefile.k8s
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ $(K8S_YAML):
@SERVICE_NAME=$(APPNAME) SERVICE_IP=$(SERVICE_IP) \
envsubst < $@.yaml | kubectl --kubeconfig=$(KUBECONFIG) apply -f -

# TODO understand WTH
# deploy_k8s: apicrud-backend media_config
deploy_k8s: apicrud-backend media_config

deploy_local: envsubst apicrud-backend secrets
ifeq ($(TAG),)
@echo Please specify an existing tag, e.g. bld_abcdefg or latest
Expand All @@ -74,25 +70,18 @@ ifeq ($(TAG),)
@echo Please specify an existing tag in form bld_abcdefg
@exit 1
endif
APP_ENV=dev TAG=$(TAG) deploy_k8s example-api example-worker \
APP_ENV=dev TAG=$(TAG) apicrud-backend example-api example-worker \
example-ui

deploy_prod: $(APPNAME)-api/tag $(APPNAME)-worker/tag
APP_ENV=prod make deploy_k8s example-api example-worker \
APP_ENV=prod make apicrud-backend example-api example-worker \
example-ui

$(APPNAME)-%/tag:
docker pull $(REGISTRY)/$(@D):latest
docker tag $(REGISTRY)/$(@D):latest $(REGISTRY)/$(@D):$(TAG)
docker push $(REGISTRY)/$(@D):$(TAG)

# TODO remove, why is this even here???
# media_config:
# kubectl create configmap example-media-config \
# --kubeconfig=$(KUBECONFIG) -o yaml --dry-run \
# --from-file=example/rbac.yaml --from-file=example/config.yaml | \
# kubectl --kubeconfig=$(KUBECONFIG) apply -f -

helm_install: /usr/local/bin/helm
helm repo add instantlinux https://instantlinux.github.io/docker-tools/
helm_list:
Expand Down
2 changes: 1 addition & 1 deletion example/helm/example-api/subcharts/api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sources:
- https://git.instantlinux.net/richb/example.git
type: application
version: 0.1.0
appVersion: "0.0.74"
appVersion: "0.2.2"
dependencies:
- name: chartlib
version: 0.1.6
Expand Down
2 changes: 1 addition & 1 deletion example/helm/example-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ media:
name: example-redis-aes-secret
key: example-redis-aes-secret
image:
tag: 0.0.36
tag: bld_e395a7e
imagePullSecrets: [ name: regcred ]
2 changes: 1 addition & 1 deletion example/helm/example-worker/subcharts/worker/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sources:
- https://git.instantlinux.net/richb/example.git
type: application
version: 0.1.0
appVersion: "0.0.74"
appVersion: "0.2.2"
dependencies:
- name: chartlib
version: 0.1.6
Expand Down
2 changes: 1 addition & 1 deletion example/helm/example-worker/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ media-worker:
queue: media
image:
repository: registry.gitlab.com/instantlinux/apicrud-media/apicrud-media-worker
tag: 0.0.36
tag: bld_e395a7e

0 comments on commit 013ca3a

Please sign in to comment.