kirby-api 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kirby/__init__.py +13 -0
- kirby/_migrations/README +1 -0
- kirby/_migrations/alembic.ini +149 -0
- kirby/_migrations/env.py +74 -0
- kirby/_migrations/script.py.mako +28 -0
- kirby/_migrations/versions/1b7affd8668e_initial_schema_users_tenants_characters_.py +129 -0
- kirby/_migrations/versions/20260424_0001_combat_tables.py +197 -0
- kirby/_migrations/versions/20260429_0001_add_combatant_jsonb.py +43 -0
- kirby/_migrations/versions/20260501_0001_codex_targeted_pages.py +54 -0
- kirby/_migrations/versions/20260501_0002_hd_relational_schema.py +652 -0
- kirby/_migrations/versions/20260501_0003_definitions_codex_chunk_id.py +74 -0
- kirby/_migrations/versions/20260503_0001_per_template_base_values.py +100 -0
- kirby/_migrations/versions/20260504_0001_pr1_relational_combat_schema.py +553 -0
- kirby/_migrations/versions/20260504_0002_seed_tactics_and_profiles.py +274 -0
- kirby/_migrations/versions/20260504_0003_backfill_combat_relational.py +410 -0
- kirby/_migrations/versions/20260504_0004_drop_combat_jsonb_columns.py +84 -0
- kirby/_migrations/versions/20260504_0005_pr1_index_audit_fills.py +127 -0
- kirby/_migrations/versions/20260504_0006_pending_phase_modifiers.py +67 -0
- kirby/_migrations/versions/20260504_0007_combat_session_scene_id.py +41 -0
- kirby/_migrations/versions/20260504_0008_morale_expires_at_seq.py +37 -0
- kirby/_migrations/versions/20260504_0009_is_stunned.py +35 -0
- kirby/_migrations/versions/20260504_0010_tactic_catalog_expansion.py +225 -0
- kirby/_migrations/versions/20260504_0011_slam_velocity_tactic.py +118 -0
- kirby/_migrations/versions/20260504_0012_mind_control_state.py +45 -0
- kirby/_migrations/versions/20260504_0013_mental_illusion_state.py +41 -0
- kirby/_migrations/versions/20260504_0014_mental_entangle_state.py +37 -0
- kirby/_migrations/versions/20260504_0015_was_surprised.py +46 -0
- kirby/_migrations/versions/20260504_0016_catalog_expansion_for_new_actions.py +203 -0
- kirby/_migrations/versions/20260504_0017_combat_started.py +37 -0
- kirby/_migrations/versions/20260504_0018_physical_entangle.py +34 -0
- kirby/_migrations/versions/20260504_0019_stat_drains.py +45 -0
- kirby/_migrations/versions/20260504_0020_continuous_effects.py +48 -0
- kirby/_migrations/versions/20260504_0021_lockout_state.py +39 -0
- kirby/_migrations/versions/20260504_0022_dispelled_powers.py +44 -0
- kirby/_migrations/versions/20260506_0001_campaign_management_v1.py +426 -0
- kirby/_migrations/versions/20260506_0002_extend_characters_for_pc.py +96 -0
- kirby/_migrations/versions/20260506_0003_combatant_control_mode.py +55 -0
- kirby/_migrations/versions/20260506_0004_brain_embeddings.py +71 -0
- kirby/_migrations/versions/20260507_0001_knowledge_tier.py +395 -0
- kirby/_migrations/versions/20260507_0002_normalize_jsonb.py +382 -0
- kirby/_migrations/versions/20260507_0003_drop_legacy_jsonb.py +180 -0
- kirby/_migrations/versions/20260507_0004_canon_embeddings.py +62 -0
- kirby/_migrations/versions/20260508_0001_comic_canon_init.py +253 -0
- kirby/_migrations/versions/20260511_0001_power_library_init.py +110 -0
- kirby/_migrations/versions/20260514_0001_combat_session_ai_provider.py +57 -0
- kirby/_migrations/versions/20260528_0001_coordinate_raw_tables.py +148 -0
- kirby/_migrations/versions/20260528_0002_coordination_initiator.py +46 -0
- kirby/_migrations/versions/20260529_0001_character_def_rename.py +28 -0
- kirby/_migrations/versions/20260529_0002_character_instance.py +53 -0
- kirby/_migrations/versions/20260529_0003_team_def.py +55 -0
- kirby/_migrations/versions/20260529_0004_team_member_def.py +40 -0
- kirby/_migrations/versions/20260529_0005_team_instance.py +56 -0
- kirby/_migrations/versions/20260529_0006_team_def_real_history.py +36 -0
- kirby/_migrations/versions/20260529_0007_team_page.py +73 -0
- kirby/_migrations/versions/20260529_0008_team_narrative.py +57 -0
- kirby/_migrations/versions/20260529_0009_migrate_org_journal_entries_to_team.py +102 -0
- kirby/_migrations/versions/20260530_0002_templates_catalog_columns.py +61 -0
- kirby/_migrations/versions/20260530_0003_reconcile_template_category_vocab.py +50 -0
- kirby/_migrations/versions/20260531_0001_align_catalog_to_engine_schema.py +44 -0
- kirby/_migrations/versions/20260601_0001_build_doc_fields.py +66 -0
- kirby/_migrations/versions/20260605_0001_proposals.py +53 -0
- kirby/_migrations/versions/20260605_0002_membership_roster.py +62 -0
- kirby/_migrations/versions/20260605_0003_xp_award.py +56 -0
- kirby/_migrations/versions/20260606_0001_base_drift_guard.py +31 -0
- kirby/_migrations/versions/20260607_0001_maneuver_details.py +50 -0
- kirby/_migrations/versions/20260609_0001_scene_wall_def_value.py +19 -0
- kirby/_migrations/versions/20260609_0002_combat_session_constructs.py +67 -0
- kirby/_migrations/versions/20260611_0001_arena_hazard_kind_status_tokens.py +32 -0
- kirby/_migrations/versions/20260611_0002_tactic_entry_role.py +28 -0
- kirby/_migrations/versions/20260611_0003_seed_archetype_profiles.py +596 -0
- kirby/_migrations/versions/20260612_0001_combatant_held_construct.py +29 -0
- kirby/_migrations/versions/20260613_0001_combatant_is_hidden.py +27 -0
- kirby/_migrations/versions/20260613_0002_combatant_flashed_sense.py +36 -0
- kirby/_migrations/versions/20260614_0001_construct_sense_group.py +35 -0
- kirby/_migrations/versions/20260614_0002_image_decoy.py +55 -0
- kirby/_migrations/versions/20260618_0001_character_extraction_tables.py +74 -0
- kirby/_migrations/versions/20260621_0001_combat_session_combatant_slot.py +51 -0
- kirby/_migrations/versions/20260621_0002_vpp_power.py +50 -0
- kirby/_migrations/versions/20260623_0001_power_categories.py +55 -0
- kirby/_migrations/versions/20260726_0001_combat_intent.py +64 -0
- kirby/_migrations/versions/20260727_0001_intent_checks_since_form.py +30 -0
- kirby/_migrations/versions/20260728_0001_stunned_at_sequence.py +31 -0
- kirby/_migrations/versions/20260729_0001_intent_budget_turns.py +20 -0
- kirby/_migrations/versions/20260730_0001_standable_structures.py +32 -0
- kirby/_migrations/versions/20260731_0001_climb_difficulty.py +25 -0
- kirby/_migrations/versions/20260731_0002_widen_character_object_alias.py +60 -0
- kirby/_migrations/versions/20260802_0001_identity_by_id_not_xmlid.py +76 -0
- kirby/_migrations/versions/20260803_0001_combatant_opening_state.py +89 -0
- kirby/_migrations/versions/20260804_0001_combat_random_fight.py +59 -0
- kirby/_migrations/versions/20260804_0002_presence_attack_effects.py +69 -0
- kirby/_migrations/versions/20260816_0001_template_level_power.py +52 -0
- kirby/_migrations/versions/20260831_0001_construct_no_teleport.py +30 -0
- kirby/_migrations/versions/20260831_0002_physical_entangle_state.py +32 -0
- kirby/_migrations/versions/20260831_0003_character_object_text.py +25 -0
- kirby/_migrations/versions/20260902_0001_combatant_in_hero_id.py +53 -0
- kirby/_migrations/versions/20260902_0002_object_affects_flags.py +51 -0
- kirby/_migrations/versions/20260917_0001_session_names_a_seat.py +84 -0
- kirby/_migrations/versions/20260918_0000_drop_combat_tables.py +85 -0
- kirby/_migrations/versions/20260918_0001_harness_tables.py +231 -0
- kirby/_migrations/versions/20260918_0002_narration_speaker_id.py +40 -0
- kirby/_migrations/versions/21980c836860_add_asset_id_refs.py +45 -0
- kirby/_migrations/versions/ba28e71c955d_codex_init.py +137 -0
- kirby/admin/__init__.py +1 -0
- kirby/auth/__init__.py +1 -0
- kirby/auth/authz.py +8 -0
- kirby/auth/dependencies.py +17 -0
- kirby/auth/jwt.py +232 -0
- kirby/auth/models.py +32 -0
- kirby/auth/routes.py +30 -0
- kirby/auth/users.py +55 -0
- kirby/builds/__init__.py +9 -0
- kirby/builds/build_doc_store.py +384 -0
- kirby/builds/category_extraction.py +83 -0
- kirby/builds/cli.py +746 -0
- kirby/builds/codex_linker.py +199 -0
- kirby/builds/combatant_loader.py +180 -0
- kirby/builds/concept_to_build.py +505 -0
- kirby/builds/hdc_exporter.py +107 -0
- kirby/builds/importer.py +577 -0
- kirby/builds/json_exporter.py +277 -0
- kirby/builds/json_importer.py +553 -0
- kirby/builds/models.py +842 -0
- kirby/builds/power_categories.py +164 -0
- kirby/builds/power_library_importer.py +625 -0
- kirby/builds/power_library_service.py +258 -0
- kirby/builds/recompute.py +37 -0
- kirby/builds/routes.py +330 -0
- kirby/builds/template_provider.py +249 -0
- kirby/campaigns/__init__.py +1 -0
- kirby/campaigns/_shared.py +36 -0
- kirby/campaigns/membership_service.py +64 -0
- kirby/campaigns/models.py +1153 -0
- kirby/campaigns/routes.py +306 -0
- kirby/campaigns/routes_acl.py +232 -0
- kirby/campaigns/routes_brain.py +392 -0
- kirby/campaigns/routes_documents.py +843 -0
- kirby/campaigns/routes_knowledge.py +711 -0
- kirby/campaigns/routes_membership.py +71 -0
- kirby/campaigns/routes_relationships.py +375 -0
- kirby/campaigns/routes_roster.py +122 -0
- kirby/campaigns/routes_sessions_events.py +448 -0
- kirby/campaigns/routes_xp.py +84 -0
- kirby/campaigns/services/__init__.py +0 -0
- kirby/campaigns/services/brain.py +610 -0
- kirby/campaigns/services/conflicts.py +501 -0
- kirby/campaigns/services/embeddings.py +389 -0
- kirby/campaigns/services/extract.py +234 -0
- kirby/campaigns/services/generation.py +317 -0
- kirby/campaigns/services/legacy_translation.py +208 -0
- kirby/campaigns/services/permissions.py +266 -0
- kirby/campaigns/services/recap.py +158 -0
- kirby/characters/__init__.py +1 -0
- kirby/characters/_shared.py +18 -0
- kirby/characters/build_routes.py +95 -0
- kirby/characters/combat_seed.py +18 -0
- kirby/characters/corpus_copy.py +353 -0
- kirby/characters/models.py +427 -0
- kirby/characters/proposals/__init__.py +0 -0
- kirby/characters/proposals/routes.py +193 -0
- kirby/characters/proposals/service.py +112 -0
- kirby/characters/routes.py +574 -0
- kirby/characters/services/__init__.py +0 -0
- kirby/characters/services/character_info_backfill.py +105 -0
- kirby/characters/services/effective.py +41 -0
- kirby/characters/services/entity_service.py +430 -0
- kirby/characters/services/writeup_persistence.py +88 -0
- kirby/characters/variants_service.py +72 -0
- kirby/characters/xp_service.py +113 -0
- kirby/cli.py +125 -0
- kirby/codex/__init__.py +8 -0
- kirby/codex/cli.py +209 -0
- kirby/codex/deps.py +54 -0
- kirby/codex/models.py +215 -0
- kirby/codex/repositories.py +233 -0
- kirby/codex/routes.py +291 -0
- kirby/codex/schemas.py +97 -0
- kirby/codex/services/__init__.py +1 -0
- kirby/codex/services/embed.py +46 -0
- kirby/codex/services/extract.py +322 -0
- kirby/codex/services/index.py +68 -0
- kirby/codex/services/orchestrator.py +203 -0
- kirby/codex/services/search.py +358 -0
- kirby/codex/services/villain_extractor.py +139 -0
- kirby/codex/services/villain_writeup_linker.py +157 -0
- kirby/codex/workers.py +96 -0
- kirby/combat/__init__.py +47 -0
- kirby/combat/choosers.py +249 -0
- kirby/combat/create.py +327 -0
- kirby/combat/events.py +207 -0
- kirby/combat/harness.py +498 -0
- kirby/combat/models.py +298 -0
- kirby/combat/random_fight/__init__.py +0 -0
- kirby/combat/random_fight/models.py +77 -0
- kirby/combat/random_fight/outcome.py +40 -0
- kirby/combat/random_fight/roster.py +223 -0
- kirby/combat/random_fight/routes.py +176 -0
- kirby/combat/random_fight/runner.py +259 -0
- kirby/combat/random_fight/schemas.py +99 -0
- kirby/combat/random_fight/session.py +313 -0
- kirby/combat/random_fight/worker.py +107 -0
- kirby/combat/routes.py +1122 -0
- kirby/combat/schemas.py +309 -0
- kirby/combat/services/__init__.py +1 -0
- kirby/combat/services/connection_hub.py +73 -0
- kirby/combat/services/publish.py +129 -0
- kirby/combat/services/subscriber.py +121 -0
- kirby/comic_canon/__init__.py +30 -0
- kirby/comic_canon/models.py +342 -0
- kirby/comic_canon/routes.py +385 -0
- kirby/comic_canon/services/__init__.py +0 -0
- kirby/comic_canon/services/archetypes.py +183 -0
- kirby/comic_canon/services/comic_vine.py +215 -0
- kirby/comic_canon/services/embeddings.py +85 -0
- kirby/comic_canon/services/prewarm.py +455 -0
- kirby/comic_canon/services/text_clean.py +28 -0
- kirby/engines/__init__.py +1 -0
- kirby/engines/cost/__init__.py +46 -0
- kirby/engines/cost/hdc.py +200 -0
- kirby/library/__init__.py +1 -0
- kirby/main.py +283 -0
- kirby/media/__init__.py +11 -0
- kirby/media/asset_uses.py +36 -0
- kirby/media/client.py +29 -0
- kirby/media/routes.py +168 -0
- kirby/media/schemas.py +31 -0
- kirby/media/taxonomy.py +33 -0
- kirby/settings.py +113 -0
- kirby/shared/__init__.py +1 -0
- kirby/shared/db.py +69 -0
- kirby/teams/__init__.py +0 -0
- kirby/teams/models.py +209 -0
- kirby/teams/routes.py +234 -0
- kirby/teams/schemas.py +123 -0
- kirby/teams/services/__init__.py +0 -0
- kirby/teams/services/effective.py +63 -0
- kirby/templates/__init__.py +1 -0
- kirby/tenants/__init__.py +1 -0
- kirby/tenants/models.py +89 -0
- kirby/tenants/routes.py +145 -0
- kirby/users/__init__.py +0 -0
- kirby/users/routes.py +40 -0
- kirby/version.py +97 -0
- kirby_api-0.1.0.dist-info/METADATA +273 -0
- kirby_api-0.1.0.dist-info/RECORD +248 -0
- kirby_api-0.1.0.dist-info/WHEEL +5 -0
- kirby_api-0.1.0.dist-info/entry_points.txt +4 -0
- kirby_api-0.1.0.dist-info/licenses/LICENSE +170 -0
- kirby_api-0.1.0.dist-info/top_level.txt +1 -0
kirby/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Kirby — HERO System VTT backend API."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version as _dist_version
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
# pyproject's [project] version is the ONE place the number lives. It was
|
|
7
|
+
# written out here too and had already drifted — the wheel said 0.1.0
|
|
8
|
+
# while the startup banner and /openapi.json both said 0.0.1.
|
|
9
|
+
__version__ = _dist_version("kirby-api")
|
|
10
|
+
except PackageNotFoundError: # pragma: no cover — source tree, never installed
|
|
11
|
+
# Not a fallback value to run on: it says it does not know rather than
|
|
12
|
+
# naming a version that would be wrong.
|
|
13
|
+
__version__ = "0+unknown"
|
kirby/_migrations/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Generic single-database configuration.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# A generic, single database configuration.
|
|
2
|
+
|
|
3
|
+
[alembic]
|
|
4
|
+
# path to migration scripts.
|
|
5
|
+
# this is typically a path given in POSIX (e.g. forward slashes)
|
|
6
|
+
# format, relative to the token %(here)s which refers to the location of this
|
|
7
|
+
# ini file
|
|
8
|
+
script_location = %(here)s
|
|
9
|
+
|
|
10
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
11
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
|
12
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
13
|
+
# for all available tokens
|
|
14
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
15
|
+
# Or organize into date-based subdirectories (requires recursive_version_locations = true)
|
|
16
|
+
# file_template = %%(year)d/%%(month).2d/%%(day).2d_%%(hour).2d%%(minute).2d_%%(second).2d_%%(rev)s_%%(slug)s
|
|
17
|
+
|
|
18
|
+
# sys.path path, will be prepended to sys.path if present.
|
|
19
|
+
# defaults to the current working directory. for multiple paths, the path separator
|
|
20
|
+
# is defined by "path_separator" below.
|
|
21
|
+
prepend_sys_path = .
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# timezone to use when rendering the date within the migration file
|
|
25
|
+
# as well as the filename.
|
|
26
|
+
# If specified, requires the tzdata library which can be installed by adding
|
|
27
|
+
# `alembic[tz]` to the pip requirements.
|
|
28
|
+
# string value is passed to ZoneInfo()
|
|
29
|
+
# leave blank for localtime
|
|
30
|
+
# timezone =
|
|
31
|
+
|
|
32
|
+
# max length of characters to apply to the "slug" field
|
|
33
|
+
# truncate_slug_length = 40
|
|
34
|
+
|
|
35
|
+
# set to 'true' to run the environment during
|
|
36
|
+
# the 'revision' command, regardless of autogenerate
|
|
37
|
+
# revision_environment = false
|
|
38
|
+
|
|
39
|
+
# set to 'true' to allow .pyc and .pyo files without
|
|
40
|
+
# a source .py file to be detected as revisions in the
|
|
41
|
+
# versions/ directory
|
|
42
|
+
# sourceless = false
|
|
43
|
+
|
|
44
|
+
# version location specification; This defaults
|
|
45
|
+
# to <script_location>/versions. When using multiple version
|
|
46
|
+
# directories, initial revisions must be specified with --version-path.
|
|
47
|
+
# The path separator used here should be the separator specified by "path_separator"
|
|
48
|
+
# below.
|
|
49
|
+
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
|
|
50
|
+
|
|
51
|
+
# path_separator; This indicates what character is used to split lists of file
|
|
52
|
+
# paths, including version_locations and prepend_sys_path within configparser
|
|
53
|
+
# files such as alembic.ini.
|
|
54
|
+
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
|
|
55
|
+
# to provide os-dependent path splitting.
|
|
56
|
+
#
|
|
57
|
+
# Note that in order to support legacy alembic.ini files, this default does NOT
|
|
58
|
+
# take place if path_separator is not present in alembic.ini. If this
|
|
59
|
+
# option is omitted entirely, fallback logic is as follows:
|
|
60
|
+
#
|
|
61
|
+
# 1. Parsing of the version_locations option falls back to using the legacy
|
|
62
|
+
# "version_path_separator" key, which if absent then falls back to the legacy
|
|
63
|
+
# behavior of splitting on spaces and/or commas.
|
|
64
|
+
# 2. Parsing of the prepend_sys_path option falls back to the legacy
|
|
65
|
+
# behavior of splitting on spaces, commas, or colons.
|
|
66
|
+
#
|
|
67
|
+
# Valid values for path_separator are:
|
|
68
|
+
#
|
|
69
|
+
# path_separator = :
|
|
70
|
+
# path_separator = ;
|
|
71
|
+
# path_separator = space
|
|
72
|
+
# path_separator = newline
|
|
73
|
+
#
|
|
74
|
+
# Use os.pathsep. Default configuration used for new projects.
|
|
75
|
+
path_separator = os
|
|
76
|
+
|
|
77
|
+
# set to 'true' to search source files recursively
|
|
78
|
+
# in each "version_locations" directory
|
|
79
|
+
# new in Alembic version 1.10
|
|
80
|
+
# recursive_version_locations = false
|
|
81
|
+
|
|
82
|
+
# the output encoding used when revision files
|
|
83
|
+
# are written from script.py.mako
|
|
84
|
+
# output_encoding = utf-8
|
|
85
|
+
|
|
86
|
+
# database URL. This is consumed by the user-maintained env.py script only.
|
|
87
|
+
# other means of configuring database URLs may be customized within the env.py
|
|
88
|
+
# file.
|
|
89
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
[post_write_hooks]
|
|
93
|
+
# post_write_hooks defines scripts or Python functions that are run
|
|
94
|
+
# on newly generated revision scripts. See the documentation for further
|
|
95
|
+
# detail and examples
|
|
96
|
+
|
|
97
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
98
|
+
# hooks = black
|
|
99
|
+
# black.type = console_scripts
|
|
100
|
+
# black.entrypoint = black
|
|
101
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
102
|
+
|
|
103
|
+
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
|
|
104
|
+
# hooks = ruff
|
|
105
|
+
# ruff.type = module
|
|
106
|
+
# ruff.module = ruff
|
|
107
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
108
|
+
|
|
109
|
+
# Alternatively, use the exec runner to execute a binary found on your PATH
|
|
110
|
+
# hooks = ruff
|
|
111
|
+
# ruff.type = exec
|
|
112
|
+
# ruff.executable = ruff
|
|
113
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
114
|
+
|
|
115
|
+
# Logging configuration. This is also consumed by the user-maintained
|
|
116
|
+
# env.py script only.
|
|
117
|
+
[loggers]
|
|
118
|
+
keys = root,sqlalchemy,alembic
|
|
119
|
+
|
|
120
|
+
[handlers]
|
|
121
|
+
keys = console
|
|
122
|
+
|
|
123
|
+
[formatters]
|
|
124
|
+
keys = generic
|
|
125
|
+
|
|
126
|
+
[logger_root]
|
|
127
|
+
level = WARNING
|
|
128
|
+
handlers = console
|
|
129
|
+
qualname =
|
|
130
|
+
|
|
131
|
+
[logger_sqlalchemy]
|
|
132
|
+
level = WARNING
|
|
133
|
+
handlers =
|
|
134
|
+
qualname = sqlalchemy.engine
|
|
135
|
+
|
|
136
|
+
[logger_alembic]
|
|
137
|
+
level = INFO
|
|
138
|
+
handlers =
|
|
139
|
+
qualname = alembic
|
|
140
|
+
|
|
141
|
+
[handler_console]
|
|
142
|
+
class = StreamHandler
|
|
143
|
+
args = (sys.stderr,)
|
|
144
|
+
level = NOTSET
|
|
145
|
+
formatter = generic
|
|
146
|
+
|
|
147
|
+
[formatter_generic]
|
|
148
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
149
|
+
datefmt = %H:%M:%S
|
kirby/_migrations/env.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Alembic environment — wired to Kirby's SQLAlchemy Base and settings.
|
|
2
|
+
|
|
3
|
+
This directory IS the alembic environment, and it lives inside the package on
|
|
4
|
+
purpose: a wheel can only carry files under a package, so `pip install
|
|
5
|
+
kirby-api` + `kirby-api migrate` and a bare `alembic upgrade head` in a
|
|
6
|
+
checkout run the same env.py against the same versions/ tree.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from logging.config import fileConfig
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from sqlalchemy import engine_from_config, pool
|
|
13
|
+
from alembic import context
|
|
14
|
+
|
|
15
|
+
from kirby.shared.db import Base
|
|
16
|
+
from kirby.settings import settings
|
|
17
|
+
|
|
18
|
+
# Import all models so Base.metadata knows about every table.
|
|
19
|
+
import kirby.auth.models # noqa: F401
|
|
20
|
+
import kirby.tenants.models # noqa: F401
|
|
21
|
+
import kirby.characters.models # noqa: F401
|
|
22
|
+
import kirby.campaigns.models # noqa: F401
|
|
23
|
+
import kirby.codex.models # noqa: F401
|
|
24
|
+
import kirby.combat.models # noqa: F401
|
|
25
|
+
import kirby.combat.random_fight.models # noqa: F401
|
|
26
|
+
|
|
27
|
+
config = context.config
|
|
28
|
+
|
|
29
|
+
# Override sqlalchemy.url from our settings (env-var driven, not alembic.ini).
|
|
30
|
+
config.set_main_option("sqlalchemy.url", settings.database_url)
|
|
31
|
+
|
|
32
|
+
# Logging comes from the ini NEXT TO THIS FILE, never from whichever ini
|
|
33
|
+
# invoked us. The repo-root alembic.ini is a two-line pointer and the
|
|
34
|
+
# `kirby-api migrate` entry point builds its Config in memory with no ini at
|
|
35
|
+
# all; reading `config.config_file_name` would give each of those three doors
|
|
36
|
+
# a different logging setup, or a KeyError on the ones with no [formatters]
|
|
37
|
+
# section. One file owns it.
|
|
38
|
+
_PACKAGED_INI = Path(__file__).resolve().parent / "alembic.ini"
|
|
39
|
+
if _PACKAGED_INI.is_file():
|
|
40
|
+
fileConfig(str(_PACKAGED_INI))
|
|
41
|
+
|
|
42
|
+
target_metadata = Base.metadata
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def run_migrations_offline() -> None:
|
|
46
|
+
url = config.get_main_option("sqlalchemy.url")
|
|
47
|
+
context.configure(
|
|
48
|
+
url=url,
|
|
49
|
+
target_metadata=target_metadata,
|
|
50
|
+
literal_binds=True,
|
|
51
|
+
dialect_opts={"paramstyle": "named"},
|
|
52
|
+
)
|
|
53
|
+
with context.begin_transaction():
|
|
54
|
+
context.run_migrations()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run_migrations_online() -> None:
|
|
58
|
+
connectable = engine_from_config(
|
|
59
|
+
config.get_section(config.config_ini_section, {}),
|
|
60
|
+
prefix="sqlalchemy.",
|
|
61
|
+
poolclass=pool.NullPool,
|
|
62
|
+
)
|
|
63
|
+
with connectable.connect() as connection:
|
|
64
|
+
context.configure(
|
|
65
|
+
connection=connection, target_metadata=target_metadata
|
|
66
|
+
)
|
|
67
|
+
with context.begin_transaction():
|
|
68
|
+
context.run_migrations()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if context.is_offline_mode():
|
|
72
|
+
run_migrations_offline()
|
|
73
|
+
else:
|
|
74
|
+
run_migrations_online()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""${message}
|
|
2
|
+
|
|
3
|
+
Revision ID: ${up_revision}
|
|
4
|
+
Revises: ${down_revision | comma,n}
|
|
5
|
+
Create Date: ${create_date}
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
${imports if imports else ""}
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = ${repr(up_revision)}
|
|
16
|
+
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
"""Upgrade schema."""
|
|
23
|
+
${upgrades if upgrades else "pass"}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def downgrade() -> None:
|
|
27
|
+
"""Downgrade schema."""
|
|
28
|
+
${downgrades if downgrades else "pass"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""initial schema: users, tenants, characters, campaigns
|
|
2
|
+
|
|
3
|
+
Revision ID: 1b7affd8668e
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2026-04-13 16:11:02.258931
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = '1b7affd8668e'
|
|
16
|
+
down_revision: Union[str, Sequence[str], None] = None
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
"""Upgrade schema."""
|
|
23
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
24
|
+
op.create_table('users',
|
|
25
|
+
sa.Column('id', sa.Uuid(), nullable=False),
|
|
26
|
+
sa.Column('sub', sa.String(length=64), nullable=False, comment='Authentik user ID from JWT sub claim'),
|
|
27
|
+
sa.Column('display_name', sa.String(length=128), nullable=True),
|
|
28
|
+
sa.Column('email', sa.String(length=255), nullable=True),
|
|
29
|
+
sa.Column('is_admin', sa.Boolean(), nullable=False, comment='Platform-wide admin (PeterB)'),
|
|
30
|
+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
31
|
+
sa.Column('last_seen_at', sa.DateTime(timezone=True), nullable=True),
|
|
32
|
+
sa.PrimaryKeyConstraint('id')
|
|
33
|
+
)
|
|
34
|
+
op.create_index(op.f('ix_users_sub'), 'users', ['sub'], unique=True)
|
|
35
|
+
op.create_table('tenants',
|
|
36
|
+
sa.Column('id', sa.Uuid(), nullable=False),
|
|
37
|
+
sa.Column('slug', sa.String(length=64), nullable=False, comment="URL-safe identifier (e.g. 'throwback')"),
|
|
38
|
+
sa.Column('name', sa.String(length=128), nullable=False, comment="Display name (e.g. 'Throwback Champions Campaign')"),
|
|
39
|
+
sa.Column('description', sa.Text(), nullable=True),
|
|
40
|
+
sa.Column('owner_id', sa.Uuid(), nullable=False, comment='The user who created/owns this tenant'),
|
|
41
|
+
sa.Column('is_active', sa.Boolean(), nullable=False),
|
|
42
|
+
sa.Column('feature_character_editor', sa.Boolean(), nullable=False, comment='When TRUE, enables the from-scratch character builder. Default OFF — HDC import + read-only view only.'),
|
|
43
|
+
sa.Column('subscription_status', sa.String(length=32), nullable=True),
|
|
44
|
+
sa.Column('subscription_plan', sa.String(length=32), nullable=True),
|
|
45
|
+
sa.Column('stripe_customer_id', sa.String(length=64), nullable=True),
|
|
46
|
+
sa.Column('stripe_subscription_id', sa.String(length=64), nullable=True),
|
|
47
|
+
sa.Column('hd_license_id', sa.String(length=64), nullable=True, comment='HD license ID bundled with SaaS subscription'),
|
|
48
|
+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
49
|
+
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
50
|
+
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
|
51
|
+
sa.PrimaryKeyConstraint('id')
|
|
52
|
+
)
|
|
53
|
+
op.create_index(op.f('ix_tenants_slug'), 'tenants', ['slug'], unique=True)
|
|
54
|
+
op.create_table('campaigns',
|
|
55
|
+
sa.Column('id', sa.Uuid(), nullable=False),
|
|
56
|
+
sa.Column('tenant_id', sa.Uuid(), nullable=False),
|
|
57
|
+
sa.Column('name', sa.String(length=128), nullable=False),
|
|
58
|
+
sa.Column('description', sa.Text(), nullable=True),
|
|
59
|
+
sa.Column('genre', sa.String(length=32), nullable=False, comment='champions | fantasy | star | pulp | modern | western | horror | dark | galactic'),
|
|
60
|
+
sa.Column('template_name', sa.String(length=64), nullable=False, comment='Default HDT template for characters in this campaign'),
|
|
61
|
+
sa.Column('gm_user_id', sa.Uuid(), nullable=False, comment='The GM running this campaign'),
|
|
62
|
+
sa.Column('is_active', sa.Boolean(), nullable=False),
|
|
63
|
+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
64
|
+
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
65
|
+
sa.ForeignKeyConstraint(['gm_user_id'], ['users.id'], ),
|
|
66
|
+
sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
|
|
67
|
+
sa.PrimaryKeyConstraint('id')
|
|
68
|
+
)
|
|
69
|
+
op.create_index(op.f('ix_campaigns_tenant_id'), 'campaigns', ['tenant_id'], unique=False)
|
|
70
|
+
op.create_table('characters',
|
|
71
|
+
sa.Column('id', sa.Uuid(), nullable=False),
|
|
72
|
+
sa.Column('tenant_id', sa.Uuid(), nullable=False),
|
|
73
|
+
sa.Column('owner_id', sa.Uuid(), nullable=False, comment='The user who imported/created this character'),
|
|
74
|
+
sa.Column('name', sa.String(length=128), nullable=False),
|
|
75
|
+
sa.Column('player_name', sa.String(length=128), nullable=True),
|
|
76
|
+
sa.Column('alternate_identities', sa.String(length=256), nullable=True),
|
|
77
|
+
sa.Column('template_name', sa.String(length=64), nullable=False, comment='HDT template used for cost calculation'),
|
|
78
|
+
sa.Column('base_points', sa.Integer(), nullable=False),
|
|
79
|
+
sa.Column('disad_points', sa.Integer(), nullable=False),
|
|
80
|
+
sa.Column('experience', sa.Integer(), nullable=False),
|
|
81
|
+
sa.Column('total_cost', sa.Integer(), nullable=True, comment='Computed total character points spent'),
|
|
82
|
+
sa.Column('character_data', sa.JSON(), nullable=True, comment='Full character definition from HDC parser'),
|
|
83
|
+
sa.Column('source', sa.String(length=16), nullable=False, comment='hdc_import | editor | api'),
|
|
84
|
+
sa.Column('hdc_filename', sa.String(length=256), nullable=True, comment='Original HDC filename if imported'),
|
|
85
|
+
sa.Column('current_stun', sa.Integer(), nullable=True),
|
|
86
|
+
sa.Column('current_body', sa.Integer(), nullable=True),
|
|
87
|
+
sa.Column('current_end', sa.Integer(), nullable=True),
|
|
88
|
+
sa.Column('is_npc', sa.Boolean(), nullable=False),
|
|
89
|
+
sa.Column('is_active', sa.Boolean(), nullable=False),
|
|
90
|
+
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
|
91
|
+
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
|
92
|
+
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
|
93
|
+
sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
|
|
94
|
+
sa.PrimaryKeyConstraint('id')
|
|
95
|
+
)
|
|
96
|
+
op.create_index(op.f('ix_characters_owner_id'), 'characters', ['owner_id'], unique=False)
|
|
97
|
+
op.create_index(op.f('ix_characters_tenant_id'), 'characters', ['tenant_id'], unique=False)
|
|
98
|
+
op.create_table('tenant_members',
|
|
99
|
+
sa.Column('id', sa.Uuid(), nullable=False),
|
|
100
|
+
sa.Column('tenant_id', sa.Uuid(), nullable=False),
|
|
101
|
+
sa.Column('user_id', sa.Uuid(), nullable=False),
|
|
102
|
+
sa.Column('role', sa.String(length=16), nullable=False, comment='owner | admin | gm | player'),
|
|
103
|
+
sa.Column('joined_at', sa.DateTime(timezone=True), nullable=False),
|
|
104
|
+
sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
|
|
105
|
+
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
|
106
|
+
sa.PrimaryKeyConstraint('id'),
|
|
107
|
+
sa.UniqueConstraint('tenant_id', 'user_id', name='uq_tenant_member')
|
|
108
|
+
)
|
|
109
|
+
op.create_index(op.f('ix_tenant_members_tenant_id'), 'tenant_members', ['tenant_id'], unique=False)
|
|
110
|
+
op.create_index(op.f('ix_tenant_members_user_id'), 'tenant_members', ['user_id'], unique=False)
|
|
111
|
+
# ### end Alembic commands ###
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def downgrade() -> None:
|
|
115
|
+
"""Downgrade schema."""
|
|
116
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
117
|
+
op.drop_index(op.f('ix_tenant_members_user_id'), table_name='tenant_members')
|
|
118
|
+
op.drop_index(op.f('ix_tenant_members_tenant_id'), table_name='tenant_members')
|
|
119
|
+
op.drop_table('tenant_members')
|
|
120
|
+
op.drop_index(op.f('ix_characters_tenant_id'), table_name='characters')
|
|
121
|
+
op.drop_index(op.f('ix_characters_owner_id'), table_name='characters')
|
|
122
|
+
op.drop_table('characters')
|
|
123
|
+
op.drop_index(op.f('ix_campaigns_tenant_id'), table_name='campaigns')
|
|
124
|
+
op.drop_table('campaigns')
|
|
125
|
+
op.drop_index(op.f('ix_tenants_slug'), table_name='tenants')
|
|
126
|
+
op.drop_table('tenants')
|
|
127
|
+
op.drop_index(op.f('ix_users_sub'), table_name='users')
|
|
128
|
+
op.drop_table('users')
|
|
129
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""combat tables
|
|
2
|
+
|
|
3
|
+
Revision ID: 20260424_0001
|
|
4
|
+
Revises: ba28e71c955d
|
|
5
|
+
Create Date: 2026-04-25
|
|
6
|
+
|
|
7
|
+
Adds the five combat tables in one atomic migration:
|
|
8
|
+
combat_template, combat_scene, combat_session, combat_event, combat_session_player.
|
|
9
|
+
|
|
10
|
+
The plan recommended merging tasks 2 and 3 into a single migration so the
|
|
11
|
+
combat_session.template_id FK is satisfiable on first-up — this is that
|
|
12
|
+
merge.
|
|
13
|
+
"""
|
|
14
|
+
from alembic import op
|
|
15
|
+
import sqlalchemy as sa
|
|
16
|
+
from sqlalchemy.dialects.postgresql import JSONB, UUID
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# revision identifiers, set by Alembic
|
|
20
|
+
revision = "20260424_0001"
|
|
21
|
+
down_revision = "ba28e71c955d"
|
|
22
|
+
branch_labels = None
|
|
23
|
+
depends_on = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def upgrade() -> None:
|
|
27
|
+
# ── combat_template (must precede combat_session for FK) ──────────────
|
|
28
|
+
op.create_table(
|
|
29
|
+
"combat_template",
|
|
30
|
+
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
|
31
|
+
sa.Column(
|
|
32
|
+
"tenant_id",
|
|
33
|
+
UUID(as_uuid=True),
|
|
34
|
+
sa.ForeignKey("tenants.id", ondelete="CASCADE"),
|
|
35
|
+
nullable=True,
|
|
36
|
+
),
|
|
37
|
+
sa.Column("name", sa.String(128), nullable=False),
|
|
38
|
+
sa.Column("edition", sa.String(8), nullable=False, server_default="6E"),
|
|
39
|
+
sa.Column("mode", sa.String(16), nullable=False, server_default="superheroic"),
|
|
40
|
+
sa.Column("payload_jsonb", JSONB, nullable=False, server_default="{}"),
|
|
41
|
+
sa.Column(
|
|
42
|
+
"created_at", sa.DateTime(timezone=True),
|
|
43
|
+
nullable=False, server_default=sa.func.now(),
|
|
44
|
+
),
|
|
45
|
+
sa.Column(
|
|
46
|
+
"updated_at", sa.DateTime(timezone=True),
|
|
47
|
+
nullable=False, server_default=sa.func.now(),
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
op.create_index(
|
|
51
|
+
"ix_combat_template_tenant_id", "combat_template", ["tenant_id"],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# ── combat_scene ──────────────────────────────────────────────────────
|
|
55
|
+
op.create_table(
|
|
56
|
+
"combat_scene",
|
|
57
|
+
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
|
58
|
+
sa.Column(
|
|
59
|
+
"tenant_id",
|
|
60
|
+
UUID(as_uuid=True),
|
|
61
|
+
sa.ForeignKey("tenants.id", ondelete="CASCADE"),
|
|
62
|
+
nullable=False,
|
|
63
|
+
),
|
|
64
|
+
sa.Column("name", sa.String(128), nullable=False),
|
|
65
|
+
sa.Column("payload_jsonb", JSONB, nullable=False, server_default="{}"),
|
|
66
|
+
sa.Column(
|
|
67
|
+
"created_at", sa.DateTime(timezone=True),
|
|
68
|
+
nullable=False, server_default=sa.func.now(),
|
|
69
|
+
),
|
|
70
|
+
sa.Column(
|
|
71
|
+
"updated_at", sa.DateTime(timezone=True),
|
|
72
|
+
nullable=False, server_default=sa.func.now(),
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
op.create_index("ix_combat_scene_tenant_id", "combat_scene", ["tenant_id"])
|
|
76
|
+
|
|
77
|
+
# ── combat_session ────────────────────────────────────────────────────
|
|
78
|
+
op.create_table(
|
|
79
|
+
"combat_session",
|
|
80
|
+
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
|
81
|
+
sa.Column(
|
|
82
|
+
"tenant_id",
|
|
83
|
+
UUID(as_uuid=True),
|
|
84
|
+
sa.ForeignKey("tenants.id", ondelete="CASCADE"),
|
|
85
|
+
nullable=False,
|
|
86
|
+
),
|
|
87
|
+
sa.Column(
|
|
88
|
+
"owner_user_id",
|
|
89
|
+
UUID(as_uuid=True),
|
|
90
|
+
sa.ForeignKey("users.id"),
|
|
91
|
+
nullable=False,
|
|
92
|
+
),
|
|
93
|
+
sa.Column(
|
|
94
|
+
"campaign_id",
|
|
95
|
+
UUID(as_uuid=True),
|
|
96
|
+
sa.ForeignKey("campaigns.id"),
|
|
97
|
+
nullable=True,
|
|
98
|
+
),
|
|
99
|
+
sa.Column("name", sa.String(255), nullable=False),
|
|
100
|
+
sa.Column("status", sa.String(16), nullable=False, server_default="setup"),
|
|
101
|
+
sa.Column(
|
|
102
|
+
"template_id",
|
|
103
|
+
UUID(as_uuid=True),
|
|
104
|
+
sa.ForeignKey("combat_template.id"),
|
|
105
|
+
nullable=False,
|
|
106
|
+
),
|
|
107
|
+
sa.Column(
|
|
108
|
+
"scene_snapshot_jsonb", JSONB,
|
|
109
|
+
nullable=False, server_default="{}",
|
|
110
|
+
),
|
|
111
|
+
sa.Column(
|
|
112
|
+
"combatants_jsonb", JSONB,
|
|
113
|
+
nullable=False, server_default="{}",
|
|
114
|
+
),
|
|
115
|
+
sa.Column(
|
|
116
|
+
"timeline_jsonb", JSONB,
|
|
117
|
+
nullable=False, server_default="{}",
|
|
118
|
+
),
|
|
119
|
+
sa.Column("dice_seed", sa.BigInteger, nullable=True),
|
|
120
|
+
sa.Column(
|
|
121
|
+
"dice_roller_kind", sa.String(16),
|
|
122
|
+
nullable=False, server_default="random",
|
|
123
|
+
),
|
|
124
|
+
sa.Column("last_sequence", sa.Integer, nullable=False, server_default="0"),
|
|
125
|
+
sa.Column(
|
|
126
|
+
"created_at", sa.DateTime(timezone=True),
|
|
127
|
+
nullable=False, server_default=sa.func.now(),
|
|
128
|
+
),
|
|
129
|
+
sa.Column(
|
|
130
|
+
"updated_at", sa.DateTime(timezone=True),
|
|
131
|
+
nullable=False, server_default=sa.func.now(),
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
op.create_index("ix_combat_session_tenant_id", "combat_session", ["tenant_id"])
|
|
135
|
+
|
|
136
|
+
# ── combat_event ──────────────────────────────────────────────────────
|
|
137
|
+
op.create_table(
|
|
138
|
+
"combat_event",
|
|
139
|
+
sa.Column("id", UUID(as_uuid=True), primary_key=True),
|
|
140
|
+
sa.Column(
|
|
141
|
+
"session_id",
|
|
142
|
+
UUID(as_uuid=True),
|
|
143
|
+
sa.ForeignKey("combat_session.id", ondelete="CASCADE"),
|
|
144
|
+
nullable=False,
|
|
145
|
+
),
|
|
146
|
+
sa.Column("sequence", sa.Integer, nullable=False),
|
|
147
|
+
sa.Column("event_type", sa.String(64), nullable=False),
|
|
148
|
+
sa.Column("author_type", sa.String(16), nullable=False),
|
|
149
|
+
sa.Column("author_id", sa.String(64), nullable=False),
|
|
150
|
+
sa.Column("payload_jsonb", JSONB, nullable=False, server_default="{}"),
|
|
151
|
+
sa.Column(
|
|
152
|
+
"created_at", sa.DateTime(timezone=True),
|
|
153
|
+
nullable=False, server_default=sa.func.now(),
|
|
154
|
+
),
|
|
155
|
+
sa.UniqueConstraint(
|
|
156
|
+
"session_id", "sequence", name="uq_combat_event_session_sequence",
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
op.create_index("ix_combat_event_session_id", "combat_event", ["session_id"])
|
|
160
|
+
|
|
161
|
+
# ── combat_session_player ─────────────────────────────────────────────
|
|
162
|
+
op.create_table(
|
|
163
|
+
"combat_session_player",
|
|
164
|
+
sa.Column(
|
|
165
|
+
"session_id",
|
|
166
|
+
UUID(as_uuid=True),
|
|
167
|
+
sa.ForeignKey("combat_session.id", ondelete="CASCADE"),
|
|
168
|
+
primary_key=True,
|
|
169
|
+
),
|
|
170
|
+
sa.Column(
|
|
171
|
+
"user_id",
|
|
172
|
+
UUID(as_uuid=True),
|
|
173
|
+
sa.ForeignKey("users.id", ondelete="CASCADE"),
|
|
174
|
+
primary_key=True,
|
|
175
|
+
),
|
|
176
|
+
sa.Column("combatant_id", sa.String(64), nullable=True),
|
|
177
|
+
sa.Column(
|
|
178
|
+
"role", sa.String(16), nullable=False, server_default="player",
|
|
179
|
+
comment="player | observer | guest",
|
|
180
|
+
),
|
|
181
|
+
sa.Column(
|
|
182
|
+
"joined_at", sa.DateTime(timezone=True),
|
|
183
|
+
nullable=False, server_default=sa.func.now(),
|
|
184
|
+
),
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def downgrade() -> None:
|
|
189
|
+
op.drop_table("combat_session_player")
|
|
190
|
+
op.drop_index("ix_combat_event_session_id", table_name="combat_event")
|
|
191
|
+
op.drop_table("combat_event")
|
|
192
|
+
op.drop_index("ix_combat_session_tenant_id", table_name="combat_session")
|
|
193
|
+
op.drop_table("combat_session")
|
|
194
|
+
op.drop_index("ix_combat_scene_tenant_id", table_name="combat_scene")
|
|
195
|
+
op.drop_table("combat_scene")
|
|
196
|
+
op.drop_index("ix_combat_template_tenant_id", table_name="combat_template")
|
|
197
|
+
op.drop_table("combat_template")
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""add combatant_jsonb column to characters
|
|
2
|
+
|
|
3
|
+
Revision ID: 20260429_0001
|
|
4
|
+
Revises: 21980c836860
|
|
5
|
+
Create Date: 2026-04-29
|
|
6
|
+
|
|
7
|
+
Stores a serialized kirby_combat.Combatant snapshot per character so
|
|
8
|
+
session creation can hydrate combat state without re-parsing the HDC.
|
|
9
|
+
|
|
10
|
+
Populated at HDC import time via EntityService; consumed at session
|
|
11
|
+
create to build combat_session.combatants_jsonb properly. Without this,
|
|
12
|
+
session.combatants_jsonb stores empty placeholder dicts and the action
|
|
13
|
+
endpoints 500 in _rehydrate_session.
|
|
14
|
+
|
|
15
|
+
Nullable so existing rows (imported before this migration when the
|
|
16
|
+
import route was stubbed) don't block the migration; they simply don't
|
|
17
|
+
participate in combat until re-imported.
|
|
18
|
+
"""
|
|
19
|
+
from alembic import op
|
|
20
|
+
import sqlalchemy as sa
|
|
21
|
+
from sqlalchemy.dialects import postgresql
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
revision = "20260429_0001"
|
|
25
|
+
down_revision = "21980c836860"
|
|
26
|
+
branch_labels = None
|
|
27
|
+
depends_on = None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def upgrade() -> None:
|
|
31
|
+
op.add_column(
|
|
32
|
+
"characters",
|
|
33
|
+
sa.Column(
|
|
34
|
+
"combatant_jsonb",
|
|
35
|
+
postgresql.JSONB(astext_type=sa.Text()),
|
|
36
|
+
nullable=True,
|
|
37
|
+
comment="Serialized kirby_combat.Combatant — populated at HDC import",
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def downgrade() -> None:
|
|
43
|
+
op.drop_column("characters", "combatant_jsonb")
|