cinchdb 0.1.0__py3-none-any.whl → 0.1.2__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.
- cinchdb/cli/commands/branch.py +9 -0
- cinchdb/cli/commands/database.py +9 -0
- cinchdb/cli/commands/tenant.py +17 -0
- cinchdb/managers/branch.py +5 -0
- cinchdb/managers/tenant.py +13 -0
- cinchdb/models/branch.py +9 -1
- cinchdb/models/database.py +9 -1
- cinchdb/models/tenant.py +9 -1
- cinchdb/utils/__init__.py +11 -1
- cinchdb/utils/name_validator.py +129 -0
- {cinchdb-0.1.0.dist-info → cinchdb-0.1.2.dist-info}/METADATA +17 -19
- {cinchdb-0.1.0.dist-info → cinchdb-0.1.2.dist-info}/RECORD +15 -30
- {cinchdb-0.1.0.dist-info → cinchdb-0.1.2.dist-info}/entry_points.txt +0 -1
- cinchdb/api/__init__.py +0 -5
- cinchdb/api/app.py +0 -76
- cinchdb/api/auth.py +0 -290
- cinchdb/api/main.py +0 -137
- cinchdb/api/routers/__init__.py +0 -25
- cinchdb/api/routers/auth.py +0 -135
- cinchdb/api/routers/branches.py +0 -368
- cinchdb/api/routers/codegen.py +0 -164
- cinchdb/api/routers/columns.py +0 -290
- cinchdb/api/routers/data.py +0 -479
- cinchdb/api/routers/databases.py +0 -177
- cinchdb/api/routers/projects.py +0 -133
- cinchdb/api/routers/query.py +0 -156
- cinchdb/api/routers/tables.py +0 -349
- cinchdb/api/routers/tenants.py +0 -216
- cinchdb/api/routers/views.py +0 -219
- {cinchdb-0.1.0.dist-info → cinchdb-0.1.2.dist-info}/WHEEL +0 -0
- {cinchdb-0.1.0.dist-info → cinchdb-0.1.2.dist-info}/licenses/LICENSE +0 -0
cinchdb/api/routers/columns.py
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
"""Columns router for CinchDB API."""
|
2
|
-
|
3
|
-
from typing import List, Optional, Any
|
4
|
-
from fastapi import APIRouter, Depends, HTTPException, Query
|
5
|
-
from pydantic import BaseModel
|
6
|
-
|
7
|
-
from cinchdb.core.database import CinchDB
|
8
|
-
from cinchdb.managers.change_applier import ChangeApplier
|
9
|
-
from cinchdb.models import Column
|
10
|
-
from cinchdb.api.auth import (
|
11
|
-
AuthContext,
|
12
|
-
require_write_permission,
|
13
|
-
require_read_permission,
|
14
|
-
)
|
15
|
-
|
16
|
-
|
17
|
-
router = APIRouter()
|
18
|
-
|
19
|
-
|
20
|
-
class ColumnInfo(BaseModel):
|
21
|
-
"""Column information."""
|
22
|
-
|
23
|
-
name: str
|
24
|
-
type: str
|
25
|
-
nullable: bool
|
26
|
-
default: Optional[str]
|
27
|
-
primary_key: bool
|
28
|
-
unique: bool
|
29
|
-
|
30
|
-
|
31
|
-
class AddColumnRequest(BaseModel):
|
32
|
-
"""Request to add a column."""
|
33
|
-
|
34
|
-
name: str
|
35
|
-
type: str
|
36
|
-
nullable: bool = True
|
37
|
-
default: Optional[str] = None
|
38
|
-
|
39
|
-
|
40
|
-
class RenameColumnRequest(BaseModel):
|
41
|
-
"""Request to rename a column."""
|
42
|
-
|
43
|
-
old_name: str
|
44
|
-
new_name: str
|
45
|
-
|
46
|
-
|
47
|
-
class AlterNullableRequest(BaseModel):
|
48
|
-
"""Request to alter column nullable constraint."""
|
49
|
-
|
50
|
-
nullable: bool
|
51
|
-
fill_value: Optional[Any] = None
|
52
|
-
|
53
|
-
|
54
|
-
@router.get("/{table}/columns", response_model=List[ColumnInfo])
|
55
|
-
async def list_columns(
|
56
|
-
table: str,
|
57
|
-
database: str = Query(..., description="Database name"),
|
58
|
-
branch: str = Query(..., description="Branch name"),
|
59
|
-
auth: AuthContext = Depends(require_read_permission),
|
60
|
-
):
|
61
|
-
"""List all columns in a table."""
|
62
|
-
db_name = database
|
63
|
-
branch_name = branch
|
64
|
-
|
65
|
-
# Check branch permissions
|
66
|
-
await require_read_permission(auth, branch_name)
|
67
|
-
|
68
|
-
try:
|
69
|
-
db = CinchDB(
|
70
|
-
database=db_name,
|
71
|
-
branch=branch_name,
|
72
|
-
tenant="main",
|
73
|
-
project_dir=auth.project_dir,
|
74
|
-
)
|
75
|
-
columns = db.columns.list_columns(table)
|
76
|
-
|
77
|
-
result = []
|
78
|
-
for col in columns:
|
79
|
-
result.append(
|
80
|
-
ColumnInfo(
|
81
|
-
name=col.name,
|
82
|
-
type=col.type,
|
83
|
-
nullable=col.nullable,
|
84
|
-
default=col.default,
|
85
|
-
primary_key=col.primary_key,
|
86
|
-
unique=col.unique,
|
87
|
-
)
|
88
|
-
)
|
89
|
-
|
90
|
-
return result
|
91
|
-
|
92
|
-
except ValueError as e:
|
93
|
-
raise HTTPException(status_code=404, detail=str(e))
|
94
|
-
|
95
|
-
|
96
|
-
@router.post("/{table}/columns")
|
97
|
-
async def add_column(
|
98
|
-
table: str,
|
99
|
-
request: AddColumnRequest,
|
100
|
-
database: str = Query(..., description="Database name"),
|
101
|
-
branch: str = Query(..., description="Branch name"),
|
102
|
-
apply: bool = Query(True, description="Apply changes to all tenants"),
|
103
|
-
auth: AuthContext = Depends(require_write_permission),
|
104
|
-
):
|
105
|
-
"""Add a new column to a table."""
|
106
|
-
db_name = database
|
107
|
-
branch_name = branch
|
108
|
-
|
109
|
-
# Check branch permissions
|
110
|
-
await require_write_permission(auth, branch_name)
|
111
|
-
|
112
|
-
# Validate type
|
113
|
-
if request.type.upper() not in ["TEXT", "INTEGER", "REAL", "BLOB", "NUMERIC"]:
|
114
|
-
raise HTTPException(
|
115
|
-
status_code=400, detail=f"Invalid column type: {request.type}"
|
116
|
-
)
|
117
|
-
|
118
|
-
try:
|
119
|
-
db = CinchDB(
|
120
|
-
database=db_name,
|
121
|
-
branch=branch_name,
|
122
|
-
tenant="main",
|
123
|
-
project_dir=auth.project_dir,
|
124
|
-
)
|
125
|
-
column = Column(
|
126
|
-
name=request.name,
|
127
|
-
type=request.type.upper(),
|
128
|
-
nullable=request.nullable,
|
129
|
-
default=request.default,
|
130
|
-
)
|
131
|
-
db.columns.add_column(table, column)
|
132
|
-
|
133
|
-
# Apply to all tenants if requested
|
134
|
-
if apply:
|
135
|
-
applier = ChangeApplier(auth.project_dir, db_name, branch_name)
|
136
|
-
applier.apply_all_unapplied()
|
137
|
-
|
138
|
-
return {"message": f"Added column '{request.name}' to table '{table}'"}
|
139
|
-
|
140
|
-
except ValueError as e:
|
141
|
-
raise HTTPException(status_code=400, detail=str(e))
|
142
|
-
|
143
|
-
|
144
|
-
@router.delete("/{table}/columns/{column}")
|
145
|
-
async def drop_column(
|
146
|
-
table: str,
|
147
|
-
column: str,
|
148
|
-
database: str = Query(..., description="Database name"),
|
149
|
-
branch: str = Query(..., description="Branch name"),
|
150
|
-
apply: bool = Query(True, description="Apply changes to all tenants"),
|
151
|
-
auth: AuthContext = Depends(require_write_permission),
|
152
|
-
):
|
153
|
-
"""Drop a column from a table."""
|
154
|
-
db_name = database
|
155
|
-
branch_name = branch
|
156
|
-
|
157
|
-
# Check branch permissions
|
158
|
-
await require_write_permission(auth, branch_name)
|
159
|
-
|
160
|
-
try:
|
161
|
-
db = CinchDB(
|
162
|
-
database=db_name,
|
163
|
-
branch=branch_name,
|
164
|
-
tenant="main",
|
165
|
-
project_dir=auth.project_dir,
|
166
|
-
)
|
167
|
-
db.columns.drop_column(table, column)
|
168
|
-
|
169
|
-
# Apply to all tenants if requested
|
170
|
-
if apply:
|
171
|
-
applier = ChangeApplier(auth.project_dir, db_name, branch_name)
|
172
|
-
applier.apply_all_unapplied()
|
173
|
-
|
174
|
-
return {"message": f"Dropped column '{column}' from table '{table}'"}
|
175
|
-
|
176
|
-
except ValueError as e:
|
177
|
-
raise HTTPException(status_code=400, detail=str(e))
|
178
|
-
|
179
|
-
|
180
|
-
@router.put("/{table}/columns/rename")
|
181
|
-
async def rename_column(
|
182
|
-
table: str,
|
183
|
-
request: RenameColumnRequest,
|
184
|
-
database: str = Query(..., description="Database name"),
|
185
|
-
branch: str = Query(..., description="Branch name"),
|
186
|
-
apply: bool = Query(True, description="Apply changes to all tenants"),
|
187
|
-
auth: AuthContext = Depends(require_write_permission),
|
188
|
-
):
|
189
|
-
"""Rename a column in a table."""
|
190
|
-
db_name = database
|
191
|
-
branch_name = branch
|
192
|
-
|
193
|
-
# Check branch permissions
|
194
|
-
await require_write_permission(auth, branch_name)
|
195
|
-
|
196
|
-
try:
|
197
|
-
db = CinchDB(
|
198
|
-
database=db_name,
|
199
|
-
branch=branch_name,
|
200
|
-
tenant="main",
|
201
|
-
project_dir=auth.project_dir,
|
202
|
-
)
|
203
|
-
db.columns.rename_column(table, request.old_name, request.new_name)
|
204
|
-
|
205
|
-
# Apply to all tenants if requested
|
206
|
-
if apply:
|
207
|
-
applier = ChangeApplier(auth.project_dir, db_name, branch_name)
|
208
|
-
applier.apply_all_unapplied()
|
209
|
-
|
210
|
-
return {
|
211
|
-
"message": f"Renamed column '{request.old_name}' to '{request.new_name}' in table '{table}'"
|
212
|
-
}
|
213
|
-
|
214
|
-
except ValueError as e:
|
215
|
-
raise HTTPException(status_code=400, detail=str(e))
|
216
|
-
|
217
|
-
|
218
|
-
@router.get("/{table}/columns/{column}")
|
219
|
-
async def get_column_info(
|
220
|
-
table: str,
|
221
|
-
column: str,
|
222
|
-
database: str = Query(..., description="Database name"),
|
223
|
-
branch: str = Query(..., description="Branch name"),
|
224
|
-
auth: AuthContext = Depends(require_read_permission),
|
225
|
-
) -> ColumnInfo:
|
226
|
-
"""Get information about a specific column."""
|
227
|
-
db_name = database
|
228
|
-
branch_name = branch
|
229
|
-
|
230
|
-
# Check branch permissions
|
231
|
-
await require_read_permission(auth, branch_name)
|
232
|
-
|
233
|
-
try:
|
234
|
-
db = CinchDB(
|
235
|
-
database=db_name,
|
236
|
-
branch=branch_name,
|
237
|
-
tenant="main",
|
238
|
-
project_dir=auth.project_dir,
|
239
|
-
)
|
240
|
-
col = db.columns.get_column_info(table, column)
|
241
|
-
|
242
|
-
return ColumnInfo(
|
243
|
-
name=col.name,
|
244
|
-
type=col.type,
|
245
|
-
nullable=col.nullable,
|
246
|
-
default=col.default,
|
247
|
-
primary_key=col.primary_key,
|
248
|
-
unique=col.unique,
|
249
|
-
)
|
250
|
-
|
251
|
-
except ValueError as e:
|
252
|
-
raise HTTPException(status_code=404, detail=str(e))
|
253
|
-
|
254
|
-
|
255
|
-
@router.put("/{table}/columns/{column}/nullable")
|
256
|
-
async def alter_column_nullable(
|
257
|
-
table: str,
|
258
|
-
column: str,
|
259
|
-
request: AlterNullableRequest,
|
260
|
-
database: str = Query(..., description="Database name"),
|
261
|
-
branch: str = Query(..., description="Branch name"),
|
262
|
-
apply: bool = Query(True, description="Apply changes to all tenants"),
|
263
|
-
auth: AuthContext = Depends(require_write_permission),
|
264
|
-
):
|
265
|
-
"""Change the nullable constraint on a column."""
|
266
|
-
db_name = database
|
267
|
-
branch_name = branch
|
268
|
-
|
269
|
-
# Check branch permissions
|
270
|
-
await require_write_permission(auth, branch_name)
|
271
|
-
|
272
|
-
try:
|
273
|
-
db = CinchDB(
|
274
|
-
database=db_name,
|
275
|
-
branch=branch_name,
|
276
|
-
tenant="main",
|
277
|
-
project_dir=auth.project_dir,
|
278
|
-
)
|
279
|
-
db.columns.alter_column_nullable(table, column, request.nullable, request.fill_value)
|
280
|
-
|
281
|
-
# Apply to all tenants if requested
|
282
|
-
if apply:
|
283
|
-
applier = ChangeApplier(auth.project_dir, db_name, branch_name)
|
284
|
-
applier.apply_all_unapplied()
|
285
|
-
|
286
|
-
action = "nullable" if request.nullable else "NOT NULL"
|
287
|
-
return {"message": f"Made column '{column}' {action} in table '{table}'"}
|
288
|
-
|
289
|
-
except ValueError as e:
|
290
|
-
raise HTTPException(status_code=400, detail=str(e))
|