PHPackages                             openstore/schema-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. openstore/schema-core

ActiveLibrary[Database &amp; ORM](/categories/database)

openstore/schema-core
=====================

Openstore core schema

0.51.6(7y ago)14571[3 PRs](https://github.com/belgattitude/openstore-schema-core/pulls)MITPHPPHP ^7.1CI failing

Since Dec 21Pushed 4y ago2 watchersCompare

[ Source](https://github.com/belgattitude/openstore-schema-core)[ Packagist](https://packagist.org/packages/openstore/schema-core)[ Docs](https://github.com/belgattitude/openstore-schema-core)[ RSS](/packages/openstore-schema-core/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)Dependencies (13)Versions (33)Used By (0)

Openstore Schema Core
=====================

[](#openstore-schema-core)

[![PHP Version](https://camo.githubusercontent.com/375e8de41f75571c97dd554f5c9f27ae12cd39c71eb6a02478a79f5962e5801e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e312b2d6666363962342e737667)](https://packagist.org/packages/begattitude/openstore-schema-core)[![Build Status](https://camo.githubusercontent.com/54822f8ed012634911dc40b4cbf7957bdea09f94d1ff98bf4c0734abb9e67c7c/68747470733a2f2f7472617669732d63692e6f72672f62656c6761747469747564652f6f70656e73746f72652d736368656d612d636f72652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/belgattitude/openstore-schema-core)[![Latest Stable Version](https://camo.githubusercontent.com/ad341cb1f5213dd6ef112fa43fc2777b0674678aa235a26365b0d420236c8cc1/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e73746f72652f736368656d612d636f72652f762f737461626c652e737667)](https://packagist.org/packages/openstore/schema-core)[![Total Downloads](https://camo.githubusercontent.com/674f5ade026ef40f33e67dbb7cdd14181f9e3e55b86855fdd621219ae1734885/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e73746f72652f736368656d612d636f72652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/openstore/schema-core)[![License](https://camo.githubusercontent.com/058f9651ad644234169b46a01fdc0d54678bee9b49734dfaf02227c17435de4a/68747470733a2f2f706f7365722e707567782e6f72672f6f70656e73746f72652f736368656d612d636f72652f6c6963656e73652e706e67)](https://packagist.org/packages/openstore/schema-core)

openstore-schema-core provides a basic database schema used in the openstore project. It consists of around 80 tables specifically designed to deal with an online catalog.

> **Disclaimer: this is a work-in-progress !**

[![product_erd_image](https://github.com/belgattitude/openstore-schema-core/raw/master/docs/image/erd-zoom-product.jpg "Product erd")](https://github.com/belgattitude/openstore-schema-core/blob/master/docs/image/erd-zoom-product.jpg)

> Warning: the `openstore-schema-core` project relies on doctrine2 to facilitate schema generation. No work have been done to make entities useful through doctrine as openstore use `zend-db` for database access. In other words, schema generation works well but there's work to do if you need using doctrine for data access *(fix naming of relationship, make repositories...)*.

Requirements
------------

[](#requirements)

- PHP 7.1+
- MySQL or MariaDB with InnoDB

Features
--------

[](#features)

- Automatic schema generation from doctrine entities.
- Support for painless schema migrations.
- Provides special triggers, procedures and functions (see [extras](https://github.com/belgattitude/openstore-schema-core/blob/master/src/OpenstoreSchema/Core/Extra/MysqlExtra.php)).
- Raw sql generation. (see [generated sql](https://github.com/belgattitude/openstore-schema-core/tree/master/resources/sql))

Install
=======

[](#install)

Clone the project
-----------------

[](#clone-the-project)

```
$ git clone https://github.com/belgattitude/openstore-schema-core.git
```

*Alternatively you can install the project through composer `composer require openstore/schema-core`*

Setup
-----

[](#setup)

### Configuration

[](#configuration)

Make a copy of the [distribution config file](https://github.com/belgattitude/openstore-schema-core/blob/master/config/openstore-schema-core.config.php.dist) and edit your database parameters:

```
$ cp ./config/openstore-schema-core.config.php.dist ./config/openstore-schema-core.config.php
# Edit database parameters
$ vi ./config/openstore-schema-core.config.php
```

### Database

[](#database)

First ensure your database server is supported and enable support for `utf8mb4` charset.

DatabaseStorage engineFile formatLarge prefixMySQL 5.6+INNODB engineBarracudaOnMariadb 10+INNODB/XTRADBBarracudaOn> Note: to be able to work with `utf8mb4`check that the following parameters are present in the mysql configuration file (`my.cnf`):
>
> - `innodb_file_per_table=1`
> - `innodb_file_format=barracuda` *([default for MariaDb 10.2.2+](https://mariadb.com/kb/en/library/xtradbinnodb-server-system-variables/#innodb_file_format), removed in 10.3)*
> - `innodb_large_prefix=1` *([default for Mariadb 10.2.2+](https://mariadb.com/kb/en/library/xtradbinnodb-server-system-variables/#innodb_large_prefix), removed in 10.3)*

Then create a new database:

```
$ mysql -e "CREATE DATABASE openstore_test CHARACTER SET='utf8mb4' COLLATE='utf8mb4_unicode_ci';" -u {USER} -p
```

Commands
--------

[](#commands)

You can list the registered commands by executing:

```
$ ./bin/openstore-schema-core
```

Practically, use the following commands for:

CommandDescription`openstore:schema:create`Create a schema on a new empty database.`openstore:schema:recreate-extra`Recreate all triggers, procedures, functions...`openstore:schema:update`Apply schema migration on an existing database.> NOTE: use the option `--dump-sql` to display the DDL instead of applying onto the database. This is particularly useful to show migration needed over a production database, for example:
>
> ```
> $ ./bin/openstore-schema-core openstore:schema:update --dump-sql
> ```
>
>
>
> Will show the migrations that have to be applied on the *current* database.

FAQ
---

[](#faq)

> Caution: backup and restore recipes described below have not been for real production usage. Always be sure of what you're doing.

### Backup a database

[](#backup-a-database)

With `mysqldump`, good to backup `schema` (ddl) and `data` (inserts) in separated files, it allows to restore the data on a fresh database. As an example:

```
# 1. Backup of the schema (ddl: create tabes, routines...)
$ mysqldump -u {USER} -p --no-data --triggers --events --routines --default-character-set=utf8mb4 {DATABASE} > /{PATH}/{DATABASE}.schema.sql
# 2. Backup of the data (sql: inserts)
$ mysqldump -u {USER} -p --no-create-info --skip-triggers --complete-insert --disable-keys --default-character-set=utf8mb4 --lock-tables {DATABASE} > /{PATH}/{DATABASE}.data.sql
```

### Restore data on an newly created schema

[](#restore-data-on-an-newly-created-schema)

First perform a backup with `mysqldump` as illustrated above, then create a new schema:

```
# 1. Generate the latest openstore schema
$ ./bin/openstore-schema-core openstore:schema:create --dump-sql > /{PATH}/openstore.schema.sql
# 2. Create a new database that will hold it
$ mysql -e "create database {NEW_DATABASE} CHARSET='utf8mb4' COLLATE='utf8mb4_unicode_ci'" -u{USER} -p
# 3. Apply the latest generated schema on your newly created database
$ mysql -u {USER} -p {NEW_DATABASE}  /{PATH}/{DATABASE}.all.sql
# 3. Restore the complete backup in the new database
$ mysql -u {USER} -p {NEW_DATABASE}
