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