create_schema.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. // create_schema.php
  3. use Doctrine\DBAL\Schema\Schema;
  4. use Doctrine\Shards\DBAL\SQLAzure\SQLAzureSchemaSynchronizer;
  5. require_once 'bootstrap.php';
  6. $schema = new Schema();
  7. $products = $schema->createTable('Products');
  8. $products->addColumn('ProductID', 'integer');
  9. $products->addColumn('SupplierID', 'integer');
  10. $products->addColumn('ProductName', 'string');
  11. $products->addColumn('Price', 'decimal', array('scale' => 2, 'precision' => 12));
  12. $products->setPrimaryKey(array('ProductID'));
  13. $products->addOption('azure.federated', true);
  14. $customers = $schema->createTable('Customers');
  15. $customers->addColumn('CustomerID', 'integer');
  16. $customers->addColumn('CompanyName', 'string');
  17. $customers->addColumn('FirstName', 'string');
  18. $customers->addColumn('LastName', 'string');
  19. $customers->setPrimaryKey(array('CustomerID'));
  20. $customers->addOption('azure.federated', true);
  21. $customers->addOption('azure.federatedOnColumnName', 'CustomerID');
  22. $orders = $schema->createTable('Orders');
  23. $orders->addColumn('CustomerID', 'integer');
  24. $orders->addColumn('OrderID', 'integer');
  25. $orders->addColumn('OrderDate', 'datetime');
  26. $orders->setPrimaryKey(array('CustomerID', 'OrderID'));
  27. $orders->addOption('azure.federated', true);
  28. $orders->addOption('azure.federatedOnColumnName', 'CustomerID');
  29. $orderItems = $schema->createTable('OrderItems');
  30. $orderItems->addColumn('CustomerID', 'integer');
  31. $orderItems->addColumn('OrderID', 'integer');
  32. $orderItems->addColumn('ProductID', 'integer');
  33. $orderItems->addColumn('Quantity', 'integer');
  34. $orderItems->setPrimaryKey(array('CustomerID', 'OrderID', 'ProductID'));
  35. $orderItems->addOption('azure.federated', true);
  36. $orderItems->addOption('azure.federatedOnColumnName', 'CustomerID');
  37. // Create the Schema + Federation:
  38. $synchronizer = new SQLAzureSchemaSynchronizer($conn, $shardManager);
  39. // Or jut look at the SQL:
  40. echo implode("\n", $synchronizer->getCreateSchema($schema));
  41. $synchronizer->createSchema($schema);