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/esm/sdk.js CHANGED
@@ -13805,6 +13805,13 @@ class SchemaMigration {
13805
13805
  constructor(databases) {
13806
13806
  this.databases = databases;
13807
13807
  }
13808
+ /**
13809
+ * Check if an attribute key is a built-in field that cannot be modified
13810
+ * Built-in fields: id, createdAt, updatedAt
13811
+ */
13812
+ isBuiltInAttribute(key) {
13813
+ return key === 'id' || key === 'createdAt' || key === 'updatedAt';
13814
+ }
13808
13815
  /**
13809
13816
  * Generate migration plan by comparing current database state with target schema
13810
13817
  */
@@ -13814,9 +13821,29 @@ class SchemaMigration {
13814
13821
  // Store schema for later use in execution
13815
13822
  this._currentSchema = schema;
13816
13823
  const operations = [];
13824
+ // If databaseId is empty, create a database with id "default"
13825
+ let databaseId = schema.databaseId;
13826
+ if (!databaseId || databaseId.trim() === '') {
13827
+ databaseId = 'default';
13828
+ try {
13829
+ yield this.databases.create({
13830
+ databaseId: databaseId,
13831
+ name: 'default',
13832
+ enabled: true
13833
+ });
13834
+ }
13835
+ catch (error) {
13836
+ // If database already exists, that's fine
13837
+ if (!(error instanceof AppwriteException && error.code === 409)) {
13838
+ throw error;
13839
+ }
13840
+ }
13841
+ // Update schema.databaseId for later use
13842
+ schema.databaseId = databaseId;
13843
+ }
13817
13844
  // Get current tables
13818
13845
  const currentTables = yield this.databases.listTables({
13819
- databaseId: schema.databaseId,
13846
+ databaseId: databaseId,
13820
13847
  total: true
13821
13848
  });
13822
13849
  const currentTablesMap = new Map();
@@ -13839,6 +13866,10 @@ class SchemaMigration {
13839
13866
  // For new tables, create all attributes and indexes
13840
13867
  // Process target attributes
13841
13868
  for (const targetAttr of targetCollection.attributes) {
13869
+ // Skip built-in attributes (id, createdAt, updatedAt)
13870
+ if (this.isBuiltInAttribute(targetAttr.key)) {
13871
+ continue;
13872
+ }
13842
13873
  operations.push({
13843
13874
  type: 'createAttribute',
13844
13875
  databaseId: schema.databaseId,
@@ -13886,6 +13917,10 @@ class SchemaMigration {
13886
13917
  });
13887
13918
  // Process target attributes
13888
13919
  for (const targetAttr of targetCollection.attributes) {
13920
+ // Skip built-in attributes (id, createdAt, updatedAt)
13921
+ if (this.isBuiltInAttribute(targetAttr.key)) {
13922
+ continue;
13923
+ }
13889
13924
  const currentCol = currentColumnsMap.get(targetAttr.key);
13890
13925
  if (!currentCol) {
13891
13926
  // Column doesn't exist - create it
@@ -13921,6 +13956,10 @@ class SchemaMigration {
13921
13956
  }
13922
13957
  // Check for columns to delete (columns in current but not in target)
13923
13958
  for (const [key, currentAttr] of currentColumnsMap.entries()) {
13959
+ // Skip built-in attributes (id, createdAt, updatedAt)
13960
+ if (this.isBuiltInAttribute(key)) {
13961
+ continue;
13962
+ }
13924
13963
  const targetAttr = targetCollection.attributes.find(a => a.key === key);
13925
13964
  if (!targetAttr) {
13926
13965
  operations.push({
@@ -14341,12 +14380,22 @@ class SchemaMigration {
14341
14380
  if (!operation.attribute) {
14342
14381
  throw new Error('Attribute definition missing for createAttribute operation');
14343
14382
  }
14383
+ // Skip built-in attributes (id, createdAt, updatedAt)
14384
+ if (this.isBuiltInAttribute(operation.attribute.key)) {
14385
+ console.log(`Skipping createAttribute for built-in field: ${operation.attribute.key}`);
14386
+ break;
14387
+ }
14344
14388
  yield this.createAttribute(operation.databaseId, operation.collectionId, operation.attribute);
14345
14389
  break;
14346
14390
  case 'deleteAttribute':
14347
14391
  if (!operation.attributeKey) {
14348
14392
  throw new Error('Column key missing for deleteAttribute operation');
14349
14393
  }
14394
+ // Skip built-in attributes (id, createdAt, updatedAt)
14395
+ if (this.isBuiltInAttribute(operation.attributeKey)) {
14396
+ console.log(`Skipping deleteAttribute for built-in field: ${operation.attributeKey}`);
14397
+ break;
14398
+ }
14350
14399
  yield this.databases.deleteColumn({
14351
14400
  databaseId: operation.databaseId,
14352
14401
  tableId: operation.collectionId,
@@ -14415,45 +14464,47 @@ class SchemaMigration {
14415
14464
  key: attr.key,
14416
14465
  required: attr.required
14417
14466
  };
14467
+ // Required fields cannot have default values
14468
+ const defaultParams = attr.required ? {} : (attr.default !== undefined ? { xdefault: attr.default } : {});
14418
14469
  switch (attr.type) {
14419
14470
  case 'string':
14420
- yield this.databases.createStringColumn(Object.assign(Object.assign({}, baseParams), { size: attr.size || 255, xdefault: attr.default, array: attr.array, encrypt: attr.encrypt }));
14471
+ yield this.databases.createStringColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { size: attr.size || 255 }), defaultParams), { array: attr.array, encrypt: attr.encrypt }));
14421
14472
  break;
14422
14473
  case 'integer':
14423
- yield this.databases.createIntegerColumn(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max, xdefault: attr.default, array: attr.array }));
14474
+ yield this.databases.createIntegerColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max }), defaultParams), { array: attr.array }));
14424
14475
  break;
14425
14476
  case 'float':
14426
- yield this.databases.createFloatColumn(Object.assign(Object.assign({}, baseParams), { min: attr.min, max: attr.max, xdefault: attr.default, array: attr.array }));
14477
+ yield this.databases.createFloatColumn(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 'boolean':
14429
- yield this.databases.createBooleanColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default, array: attr.array }));
14480
+ yield this.databases.createBooleanColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
14430
14481
  break;
14431
14482
  case 'datetime':
14432
- yield this.databases.createDatetimeColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default, array: attr.array }));
14483
+ yield this.databases.createDatetimeColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
14433
14484
  break;
14434
14485
  case 'email':
14435
- yield this.databases.createEmailColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default, array: attr.array }));
14486
+ yield this.databases.createEmailColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
14436
14487
  break;
14437
14488
  case 'enum':
14438
14489
  if (!attr.elements) {
14439
14490
  throw new Error('Enum column requires elements array');
14440
14491
  }
14441
- yield this.databases.createEnumColumn(Object.assign(Object.assign({}, baseParams), { elements: attr.elements, xdefault: attr.default, array: attr.array }));
14492
+ yield this.databases.createEnumColumn(Object.assign(Object.assign(Object.assign(Object.assign({}, baseParams), { elements: attr.elements }), defaultParams), { array: attr.array }));
14442
14493
  break;
14443
14494
  case 'url':
14444
- yield this.databases.createUrlColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default, array: attr.array }));
14495
+ yield this.databases.createUrlColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
14445
14496
  break;
14446
14497
  case 'ip':
14447
- yield this.databases.createIpColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default, array: attr.array }));
14498
+ yield this.databases.createIpColumn(Object.assign(Object.assign(Object.assign({}, baseParams), defaultParams), { array: attr.array }));
14448
14499
  break;
14449
14500
  case 'point':
14450
- yield this.databases.createPointColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default }));
14501
+ yield this.databases.createPointColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
14451
14502
  break;
14452
14503
  case 'line':
14453
- yield this.databases.createLineColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default }));
14504
+ yield this.databases.createLineColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
14454
14505
  break;
14455
14506
  case 'polygon':
14456
- yield this.databases.createPolygonColumn(Object.assign(Object.assign({}, baseParams), { xdefault: attr.default }));
14507
+ yield this.databases.createPolygonColumn(Object.assign(Object.assign({}, baseParams), defaultParams));
14457
14508
  break;
14458
14509
  case 'relationship':
14459
14510
  if (!attr.relatedCollectionId) {