Databases Folder ({{ZN >= 4.3.0}})



( ZN >= 4.4.0 )

The main purpose of this method is to create the database structure using directories and files. Thus, you can easily transfer the database structure of the progeny that you created locally to the server. These creation operations occur in the Databases / directory. There are 2 more subdirectories in this directory ;

Actives / Active databases and tables to be used.
Archives / The databases and tables to be archived that will no longer be used.

There are 2 ways in which this process can be commissioned ;

Run Method
Generate::databases();
Run Command from Console
php zerocore run-class generate:databases 

With either of these methods, you can make the directories and files in the Databases / directory turn into databases and tables.

 

 

# Creating a Database


To create a database Databases / Actives / directory into exampledatabas to / directory create.

After doing this, you can see that the ExampleDatabase database is created when you use any of the above paths and refresh the page.

Generate::databases();

 

 

# Creating Tables


To create the tables, create Users.php and UserProfiles.php in the Databases / ActivesExampleDatabase / directory and fill in the contents as follows.

File: Databases / Actives / ExampleDatabase / Users.php
<?php return
[
    'user'  => [DB::varchar(100), DB::notNull()],
    'email' => [DB::varchar(100), DB::notNull()]
];
File: Databases / Actives / ExampleDatabase / UserProfiles.php
<?php return
[
    'user_id' => [DB::int(11), DB::notNull()],
    'adress'  => [DB::text()],
    'phone'   => [DB::varchar(11)]
];

If you are careful with the above usage, it is like sending data to the 2nd parameter of DBForge :: createTable () method . Another thing to note is that if the table ID value is not specified, the system generates the ID values ​​itself. After using the above, you can see the creation of tables and databases if you run them using one of the methods mentioned.

Generate::databases();

 

 

# Updating Tables


Actives / When you make changes to a table within the file directory changes from the previous final Archives / directories that are saved in a directory created under the name of the database table that is connected. I will update my file below.

File: Databases / Actives / ExampleDatabase / Users.php
<?php return
[
    'user'   => [DB::varchar(100), DB::notNull()],
    'email'  => [DB::varchar(100), DB::notNull()],
    'status' => [DB::int(1), DB::null()],
    'name'   => [DB::varchar(200), DB::null()]
];

Let's run our code.

Generate::database();

As you can see from the picture above, the system automatically copies the last version of the file before it was changed. At the end of the file , it adds the time value generated by the time () method.

 

 

# Delete Table


Actives / should be cut and pasted to the Archives / directory to delete the table . For example, I'll move the ExampleDatabase / UserProfiles.php file into the Archives / directory.

Generate::databases();

 

 

# Archive


If you make changes in any of the above changes are made to the database table files Archives / directory automatically tablo_adi_zamandamgasi.php -formed. This will archive the contents of the file before making changes. Or if you need to delete the file you need to move that directory and the file to the Archives / directory. Going to the version for deletion or changes will make a big contribution to you in the future.

As an example, let's add a new column to the UserProfiles table above. To do this, follow the steps below.

 Add the required column to the ExampleDatabase / UserProfiles.php file.

 Restart the page with one of the specified paths.

● In the  Archives / ExampleDatabase directory, you can see the creation of a file like UserProfies_1490705285.php .

  If you delete the fileyou need tocutit from Actives / directory andmove it to Archives / directory.

● If you  repeat step 2, you can see that the file has been deleted.

File: Databases / Actives / ExampleDatabase / UserProfiles.php
<?php return
[
    'user_id'    => [DB::int(11), DB::notNull()],
    'adress'     => [DB::text()],
    'first_name' => [DB::varchar(100)],
    'last_name'  => [DB::varchar(100)],
    'gender'     => [DB::int(1)],
    'phone'      => [DB::varchar(11)]
];

The fact that we automatically apply the changes means you archive the changes in each of the files and get important data for future use. In other words, the basic philosophy of this system is to create and archive. The contents of the archived file are as follows.

File: Databases / Archives / ExampleDatabase / UserProfiles_v1.php
<?php return
[
    'user_id' => [DB::int(11), DB::notNull()],
    'adress'  => [DB::text()],
    'phone'   => [DB::varchar(11)]
];
Note: Rename (rename) operations on database, table and column names can not be performed .