ソースを参照

Actualizar 'README.md'

raguilar 1 年間 前
コミット
e7931a3155
共有1 個のファイルを変更した78 個の追加0 個の削除を含む
  1. 78 0
      README.md

+ 78 - 0
README.md

@@ -149,6 +149,84 @@ Pasos detallados sobre la creación de tablas específicas, asegurando la cohere
 Ejemplo para hacer una tabla, llave primaria, llave foránea.
 ![Texto Alternativo](Images/tabla.png")
 
+Codigo para crear dos entidades Producto Categoria
+
+```php
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240201_185131_tbl_test
+ */
+class m240201_185131_tbl_test extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable('Producto', [
+            // "idProducto" => $this->primaryKey(), // Esta es una manera de volver llave primaria
+            "idProducto" => $this->string(36),  // UUID es por eso el 36
+            "idCategoria" => $this->string(36),
+            "clave" => $this->string(20),
+            "nombre" => $this->string("255"),
+            "descripcion" => $this->string("255"),            
+            "idUsuarioCreador" => $this->integer(),
+            "creado" => $this->timestamp() . " with time zone",
+            "modificado" => $this->timestamp() . " with time zone",
+            "eliminado" => $this->timestamp() . " with time zone",
+          ]);      
+          
+          $this->addPrimaryKey('ProductoPK', 'Producto', 'idProducto');
+
+          $this->createTable('Categoria', [
+            "idCategoria" => $this->string(36),
+            "clave" => $this->string(20),
+            "nombre" => $this->string("255"),
+            "descripcion" => $this->string("255"),
+            "idUsuarioCreador" => $this->integer(),
+            "creado" => $this->timestamp() . " with time zone",
+            "modificado" => $this->timestamp() . " with time zone",
+            "eliminado" => $this->timestamp() . " with time zone",
+          ]);      
+          
+          $this->addPrimaryKey('CategoriaPK', 'Categoria', 'idCategoria');
+          
+          $this->addForeignKey('ProductoIdCategoriaFK', 'Producto', 'idCategoria', 'Categoria', 'idCategoria');          
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        echo "m240201_185131_tbl_test cannot be reverted.\n";
+        $this->dropForeignKey('ProductoIdCategoriaFK', 'Producto');          
+        $this->dropTable("Producto");
+        $this->dropTable("Categoria");
+        
+    }
+
+    /*
+    // Use up()/down() to run migration code without a transaction.
+    public function up()
+    {
+
+    }
+
+    public function down()
+    {
+        echo "m240201_185131_tbl_test cannot be reverted.\n";
+
+        return false;
+    }
+    */
+}
+
+
+
 ### 7. Inicialización del servidor PHP.
 
 Instrucciones para inicializar el servidor PHP y poner en marcha la aplicación localmente.