appbuild-oceanbase-console 1.10.2 → 1.10.3
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.
- package/dist/cjs/sdk.js +64 -13
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +64 -13
- package/dist/esm/sdk.js.map +1 -1
- package/dist/iife/sdk.js +64 -13
- package/package.json +1 -1
- package/types/migrations.d.ts +5 -0
package/dist/iife/sdk.js
CHANGED
|
@@ -13808,6 +13808,13 @@
|
|
|
13808
13808
|
constructor(databases) {
|
|
13809
13809
|
this.databases = databases;
|
|
13810
13810
|
}
|
|
13811
|
+
/**
|
|
13812
|
+
* Check if an attribute key is a built-in field that cannot be modified
|
|
13813
|
+
* Built-in fields: id, createdAt, updatedAt
|
|
13814
|
+
*/
|
|
13815
|
+
isBuiltInAttribute(key) {
|
|
13816
|
+
return key === 'id' || key === 'createdAt' || key === 'updatedAt';
|
|
13817
|
+
}
|
|
13811
13818
|
/**
|
|
13812
13819
|
* Generate migration plan by comparing current database state with target schema
|
|
13813
13820
|
*/
|
|
@@ -13817,9 +13824,29 @@
|
|
|
13817
13824
|
// Store schema for later use in execution
|
|
13818
13825
|
this._currentSchema = schema;
|
|
13819
13826
|
const operations = [];
|
|
13827
|
+
// If databaseId is empty, create a database with id "default"
|
|
13828
|
+
let databaseId = schema.databaseId;
|
|
13829
|
+
if (!databaseId || databaseId.trim() === '') {
|
|
13830
|
+
databaseId = 'default';
|
|
13831
|
+
try {
|
|
13832
|
+
yield this.databases.create({
|
|
13833
|
+
databaseId: databaseId,
|
|
13834
|
+
name: 'default',
|
|
13835
|
+
enabled: true
|
|
13836
|
+
});
|
|
13837
|
+
}
|
|
13838
|
+
catch (error) {
|
|
13839
|
+
// If database already exists, that's fine
|
|
13840
|
+
if (!(error instanceof AppwriteException && error.code === 409)) {
|
|
13841
|
+
throw error;
|
|
13842
|
+
}
|
|
13843
|
+
}
|
|
13844
|
+
// Update schema.databaseId for later use
|
|
13845
|
+
schema.databaseId = databaseId;
|
|
13846
|
+
}
|
|
13820
13847
|
// Get current tables
|
|
13821
13848
|
const currentTables = yield this.databases.listTables({
|
|
13822
|
-
databaseId:
|
|
13849
|
+
databaseId: databaseId,
|
|
13823
13850
|
total: true
|
|
13824
13851
|
});
|
|
13825
13852
|
const currentTablesMap = new Map();
|
|
@@ -13842,6 +13869,10 @@
|
|
|
13842
13869
|
// For new tables, create all attributes and indexes
|
|
13843
13870
|
// Process target attributes
|
|
13844
13871
|
for (const targetAttr of targetCollection.attributes) {
|
|
13872
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
13873
|
+
if (this.isBuiltInAttribute(targetAttr.key)) {
|
|
13874
|
+
continue;
|
|
13875
|
+
}
|
|
13845
13876
|
operations.push({
|
|
13846
13877
|
type: 'createAttribute',
|
|
13847
13878
|
databaseId: schema.databaseId,
|
|
@@ -13889,6 +13920,10 @@
|
|
|
13889
13920
|
});
|
|
13890
13921
|
// Process target attributes
|
|
13891
13922
|
for (const targetAttr of targetCollection.attributes) {
|
|
13923
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
13924
|
+
if (this.isBuiltInAttribute(targetAttr.key)) {
|
|
13925
|
+
continue;
|
|
13926
|
+
}
|
|
13892
13927
|
const currentCol = currentColumnsMap.get(targetAttr.key);
|
|
13893
13928
|
if (!currentCol) {
|
|
13894
13929
|
// Column doesn't exist - create it
|
|
@@ -13924,6 +13959,10 @@
|
|
|
13924
13959
|
}
|
|
13925
13960
|
// Check for columns to delete (columns in current but not in target)
|
|
13926
13961
|
for (const [key, currentAttr] of currentColumnsMap.entries()) {
|
|
13962
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
13963
|
+
if (this.isBuiltInAttribute(key)) {
|
|
13964
|
+
continue;
|
|
13965
|
+
}
|
|
13927
13966
|
const targetAttr = targetCollection.attributes.find(a => a.key === key);
|
|
13928
13967
|
if (!targetAttr) {
|
|
13929
13968
|
operations.push({
|
|
@@ -14344,12 +14383,22 @@
|
|
|
14344
14383
|
if (!operation.attribute) {
|
|
14345
14384
|
throw new Error('Attribute definition missing for createAttribute operation');
|
|
14346
14385
|
}
|
|
14386
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
14387
|
+
if (this.isBuiltInAttribute(operation.attribute.key)) {
|
|
14388
|
+
console.log(`Skipping createAttribute for built-in field: ${operation.attribute.key}`);
|
|
14389
|
+
break;
|
|
14390
|
+
}
|
|
14347
14391
|
yield this.createAttribute(operation.databaseId, operation.collectionId, operation.attribute);
|
|
14348
14392
|
break;
|
|
14349
14393
|
case 'deleteAttribute':
|
|
14350
14394
|
if (!operation.attributeKey) {
|
|
14351
14395
|
throw new Error('Column key missing for deleteAttribute operation');
|
|
14352
14396
|
}
|
|
14397
|
+
// Skip built-in attributes (id, createdAt, updatedAt)
|
|
14398
|
+
if (this.isBuiltInAttribute(operation.attributeKey)) {
|
|
14399
|
+
console.log(`Skipping deleteAttribute for built-in field: ${operation.attributeKey}`);
|
|
14400
|
+
break;
|
|
14401
|
+
}
|
|
14353
14402
|
yield this.databases.deleteColumn({
|
|
14354
14403
|
databaseId: operation.databaseId,
|
|
14355
14404
|
tableId: operation.collectionId,
|
|
@@ -14418,45 +14467,47 @@
|
|
|
14418
14467
|
key: attr.key,
|
|
14419
14468
|
required: attr.required
|
|
14420
14469
|
};
|
|
14470
|
+
// Required fields cannot have default values
|
|
14471
|
+
const defaultParams = attr.required ? {} : (attr.default !== undefined ? { xdefault: attr.default } : {});
|
|
14421
14472
|
switch (attr.type) {
|
|
14422
14473
|
case 'string':
|
|
14423
|
-
yield this.databases.createStringColumn(Object.assign(Object.assign({}, baseParams), { size: attr.size || 255,
|
|
14474
|
+
yield this.databases.createStringColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { size: attr.size || 255 }), defaultParams), { array: attr.array, encrypt: attr.encrypt }));
|
|
14424
14475
|
break;
|
|
14425
14476
|
case 'integer':
|
|
14426
|
-
yield this.databases.createIntegerColumn(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max,
|
|
14477
|
+
yield this.databases.createIntegerColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max }), defaultParams), { array: attr.array }));
|
|
14427
14478
|
break;
|
|
14428
14479
|
case 'float':
|
|
14429
|
-
yield this.databases.createFloatColumn(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max,
|
|
14480
|
+
yield this.databases.createFloatColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max }), defaultParams), { array: attr.array }));
|
|
14430
14481
|
break;
|
|
14431
14482
|
case 'boolean':
|
|
14432
|
-
yield this.databases.createBooleanColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14483
|
+
yield this.databases.createBooleanColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14433
14484
|
break;
|
|
14434
14485
|
case 'datetime':
|
|
14435
|
-
yield this.databases.createDatetimeColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14486
|
+
yield this.databases.createDatetimeColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14436
14487
|
break;
|
|
14437
14488
|
case 'email':
|
|
14438
|
-
yield this.databases.createEmailColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14489
|
+
yield this.databases.createEmailColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14439
14490
|
break;
|
|
14440
14491
|
case 'enum':
|
|
14441
14492
|
if (!attr.elements) {
|
|
14442
14493
|
throw new Error('Enum column requires elements array');
|
|
14443
14494
|
}
|
|
14444
|
-
yield this.databases.createEnumColumn(Object.assign(Object.assign({}, baseParams), { elements: attr.elements,
|
|
14495
|
+
yield this.databases.createEnumColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { elements: attr.elements }), defaultParams), { array: attr.array }));
|
|
14445
14496
|
break;
|
|
14446
14497
|
case 'url':
|
|
14447
|
-
yield this.databases.createUrlColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14498
|
+
yield this.databases.createUrlColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14448
14499
|
break;
|
|
14449
14500
|
case 'ip':
|
|
14450
|
-
yield this.databases.createIpColumn(Object.assign(Object.assign({}, baseParams), {
|
|
14501
|
+
yield this.databases.createIpColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
|
|
14451
14502
|
break;
|
|
14452
14503
|
case 'point':
|
|
14453
|
-
yield this.databases.createPointColumn(Object.assign(Object.assign({}, baseParams),
|
|
14504
|
+
yield this.databases.createPointColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
|
|
14454
14505
|
break;
|
|
14455
14506
|
case 'line':
|
|
14456
|
-
yield this.databases.createLineColumn(Object.assign(Object.assign({}, baseParams),
|
|
14507
|
+
yield this.databases.createLineColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
|
|
14457
14508
|
break;
|
|
14458
14509
|
case 'polygon':
|
|
14459
|
-
yield this.databases.createPolygonColumn(Object.assign(Object.assign({}, baseParams),
|
|
14510
|
+
yield this.databases.createPolygonColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
|
|
14460
14511
|
break;
|
|
14461
14512
|
case 'relationship':
|
|
14462
14513
|
if (!attr.relatedCollectionId) {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "appbuild-oceanbase-console",
|
|
3
3
|
"homepage": "https://appwrite.io/support",
|
|
4
4
|
"description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API",
|
|
5
|
-
"version": "1.10.
|
|
5
|
+
"version": "1.10.3",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "dist/cjs/sdk.js",
|
|
8
8
|
"exports": {
|
package/types/migrations.d.ts
CHANGED
|
@@ -126,6 +126,11 @@ export interface MigrationPlan {
|
|
|
126
126
|
export declare class SchemaMigration {
|
|
127
127
|
private databases;
|
|
128
128
|
constructor(databases: TablesDB);
|
|
129
|
+
/**
|
|
130
|
+
* Check if an attribute key is a built-in field that cannot be modified
|
|
131
|
+
* Built-in fields: id, createdAt, updatedAt
|
|
132
|
+
*/
|
|
133
|
+
private isBuiltInAttribute;
|
|
129
134
|
/**
|
|
130
135
|
* Generate migration plan by comparing current database state with target schema
|
|
131
136
|
*/
|