Browse Source

db: Change UUID to INT

This commit changes UUID type for ID columns to INTEGER AUTO_INCREMENT.
There was a problem with UUID on PostgreSQL when it was in BYTEA format.
INTEGER is enough at this moment.
Added seeders (INSERTS for existing tables) - test data for Sequelize.
Updated .gitignore file and README.
Issue #38
tags/v0.0.41
Kamil Biały 2 years ago
parent
commit
ced5816837
13 changed files with 368 additions and 180 deletions
  1. +5
    -7
      .gitignore
  2. +22
    -4
      README.md
  3. +6
    -28
      pulsar/models/Language.php
  4. +0
    -26
      schema/config.json
  5. +6
    -10
      schema/migrations/20171016234546-language.js
  6. +7
    -13
      schema/migrations/20171017002303-menu.js
  7. +6
    -9
      schema/migrations/20171017003344-user.js
  8. +94
    -0
      schema/sample/languages.js
  9. +115
    -0
      schema/sample/menus.js
  10. +71
    -0
      schema/sample/users.js
  11. +7
    -23
      schema/schema.sql
  12. +14
    -45
      schema/test.sql
  13. +15
    -15
      tsconfig.static.json

+ 5
- 7
.gitignore View File

@@ -1,22 +1,20 @@
.sublime/*
.phalcon/*
.vs/*

public/themes/pluto/vendors/js/*
public/themes/pluto/vendors/css/*
public/themes/pluto/vendors/fonts/*

node_modules/*
pulsar/cache/*

public/themes/pluto/js/view/*
public/themes/pluto/js/typings/*
public/themes/pluto/fonts/*.*
.eslintrc.json
tslint.json
public/themes/pluto/css/font-awesome.css
cache/*
public/themes/pluto/js/bootstrap.js

app/installer/languages/*
app/admin/languages/*

public/themes/pluto/js/app.static.js
public/themes/pluto/js/app.static.js.map

package-lock.json

+ 22
- 4
README.md View File

@@ -3,14 +3,32 @@
Issues page:
http://pm.aculo.pl/projects/pulsar/

Demo page:
http://pulsar.aculo.pl/admin/login

Login on admin:
- Username: admin
- Password: admin

Login on test:
- Username: test
- Password: test

Dependencies:
- Node.js
- Phalcon
- PHP 7
- MariaDB / PostgreSQL /
- MariaDB / PostgreSQL / SQLite

Installation:

First step is to edit your config.json file placed in pulsar/config directory.
This file will not be updated from GIT.

npm install
npm install --global typescript
npm install --global sequelize-cli

npm run tsc
npm run sequelize db:migrate
npm run sequelize db:seed:all

node prepare.js

+ 6
- 28
pulsar/models/Language.php View File

@@ -21,9 +21,9 @@ use Pulsar\Helper\Utils;
class Language extends \Phalcon\Mvc\Model
{
/**
* Identyfikator języka w postaci GUID.
* Identyfikator języka.
*
* TYPE: string
* TYPE: integer
*/
public $id = null;

@@ -103,15 +103,6 @@ class Language extends \Phalcon\Mvc\Model
*/
protected static $_back_langs = [];

// =============================================================================

/**
* Identyfikator języka w formacie GUID.
*
* TYPE: string
*/
private $_id = null;

// =============================================================================

/**
@@ -138,29 +129,16 @@ class Language extends \Phalcon\Mvc\Model
}

/**
* Zwraca identyfikator języka w formacie binarnym.
* Funkcja używana przy kontrolkach, zwraca identyfikator języka.
*
* RETURNS: string
* Identyfikator języka w formacie binarnym pobrany z tabeli.
* Identyfikator języka.
*/
public function getRawId(): string
public function getId(): int
{
return $this->id;
}

/**
* Zwraca identyfikator języka w formacie GUID.
*
* RETURNS: string
* Identyfikator języka skonwertowany na typ GUID.
*/
public function getId(): string
{
if( !$this->_id )
$this->_id = Utils::BinToGUID( $this->id );
return $this->_id;
}

/**
* Sprawdza czy język jest wyłączony z użytku.
*
@@ -308,7 +286,7 @@ class Language extends \Phalcon\Mvc\Model
* $id (string):
* Identyfikator języka który ma zostać ustawiony jako aktualny.
*/
private static function findAndStore( string $id = null ): void
private static function findAndStore( int $id = null ): void
{
// pobierz języki z bazy danych
$langs = Language::find([

+ 0
- 26
schema/config.json View File

@@ -1,26 +0,0 @@
{
"development": {
"username": "root",
"password": "",
"database": "pulsar",
"host": "127.0.0.1",
"dialect": "mysql",
"migrationStorageTableName": "sequelize_meta"
},
"test": {
"username": "root",
"password": "",
"database": "pluto",
"host": "127.0.0.1",
"dialect": "mysql",
"migrationStorageTableName": "sequelize_meta"
},
"production": {
"username": "root",
"password": "",
"database": "pluto",
"host": "127.0.0.1",
"dialect": "mysql",
"migrationStorageTableName": "sequelize_meta"
}
}

+ 6
- 10
schema/migrations/20171016234546-language.js View File

@@ -13,18 +13,13 @@
* this program. If not, see <http://www.licenses.aculo.pl/>.
*/

/**
* Tworzy tabelę z językami strony.
*
* Lista języków dostepnych na stronie i/lub dla panelu administratora.
* Informacje o zasadach odnośnie zapisu kodu języka można znaleźć pod adresem:
* https://www.w3.org/International/articles/language-tags/
*/
module.exports = {
up: ( queryInterface, Sequelize ) => {
up: (queryInterface, Sequelize) =>
{
return queryInterface.createTable( "language", {
id: {
type: Sequelize.CHAR(16).BINARY,
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
@@ -62,7 +57,8 @@ module.exports = {
} );
},

down: ( queryInterface, Sequelize ) => {
down: (queryInterface, Sequelize) =>
{
return queryInterface.dropTable( "language" );
}
};

+ 7
- 13
schema/migrations/20171017002303-menu.js View File

@@ -13,25 +13,18 @@
* this program. If not, see <http://www.licenses.aculo.pl/>.
*/

/**
* Tworzy tabelę dla menu.
*
* Do menu przypisywane są strony, do których zaś przypinane są artykuły.
* Menu można podpiąć do wybranego kontenera na stronie.
* Istnieją również prywatne menu które nie mogą być wybrane i wyświetlane.
* Domyślne utworzone prywatne menu systemowe, to menu ze stronami błędów.
* Każde utworzone menu można wyłączyć przełączając pole "online".
*/
module.exports = {
up: ( queryInterface, Sequelize ) => {
up: (queryInterface, Sequelize) =>
{
return queryInterface.createTable( "menu", {
id: {
type: Sequelize.CHAR(16).BINARY,
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
id_language: {
type: Sequelize.CHAR(16).BINARY,
type: Sequelize.INTEGER,
primaryKey: true,
allowNull: false,
references: {
@@ -62,7 +55,8 @@ module.exports = {
} );
},

down: ( queryInterface, Sequelize ) => {
down: (queryInterface, Sequelize) =>
{
return queryInterface.dropTable( "menu" );
}
};

+ 6
- 9
schema/migrations/20171017003344-user.js View File

@@ -13,17 +13,13 @@
* this program. If not, see <http://www.licenses.aculo.pl/>.
*/

/**
* Tworzy tabelę dla użytkowników.
*
* Na chwilę obecną jest to prosta lista pól które są obowiązkowe dla każdego
* użytkownika.
*/
module.exports = {
up: ( queryInterface, Sequelize ) => {
up: (queryInterface, Sequelize) =>
{
return queryInterface.createTable( "user", {
id: {
type: Sequelize.CHAR(16).BINARY,
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
@@ -59,7 +55,8 @@ module.exports = {
} );
},

down: ( queryInterface, Sequelize ) => {
down: (queryInterface, Sequelize) =>
{
return queryInterface.dropTable( "user" );
}
};

+ 94
- 0
schema/sample/languages.js View File

@@ -0,0 +1,94 @@
/*
* This file is part of Pulsar CMS
* Copyright (c) by sobiemir <sobiemir@aculo.pl>
* ___ __
* / _ \__ __/ /__ ___ _____
* / ___/ // / (_-</ _ `/ __/
* /_/ \_,_/_/___/\_,_/_/
*
* This source file is subject to the New BSD License that is bundled
* with this package in the file LICENSE.txt.
*
* You should have received a copy of the New BSD License along with
* this program. If not, see <http://www.licenses.aculo.pl/>.
*/

const languages = [{
id: 1,
frontend: true,
backend: true,
direction: "L",
order: 1,
code: "pl",
default_name: "Polski"
}, {
id: 2,
frontend: true,
backend: true,
direction: "L",
order: 2,
code: "en",
default_name: "English"
}, {
id: 3,
frontend: true,
backend: false,
direction: "L",
order: 3,
code: "ru",
default_name: "Русский"
}, {
id: 4,
frontend: false,
backend: true,
direction: "L",
order: 4,
code: "de",
default_name: "Deutsch"
}, {
id: 5,
frontend: false,
backend: false,
direction: "L",
order: 5,
code: "ko",
default_name: "한국어"
}];

module.exports = {
// wgrywanie danych testowych
up: (queryInterface, Sequelize) =>
{
// utwórz zapytanie sprawdzające czy istnieją już jakieś dane w tabeli
let sql = queryInterface.QueryGenerator.selectQuery( "language", {
limit: 1
} );
// i wykonaj je
return queryInterface.sequelize.query( sql, {
type: Sequelize.QueryTypes.SELECT,
raw: true
} ).then( (data) => {
// jeżeli istnieją, zwróć wyjątek
if( data.length > 0 )
throw "You can insert test data only to empty table."

// jeżeli nie, wgraj dane testowe
return queryInterface.bulkInsert( "language", languages );
} );
},

// usuwanie danych testowych
down: (queryInterface, Sequelize) =>
{
// utwórz warunki - sprawdzaj czy element zgadza się z tym wgrywanym
const elems = [];
for( const language of languages )
elems.push( queryInterface.bulkDelete("language", {
"id": language.id,
"code": language.code,
"default_name": language.default_name
}) );
// wykonaj wszystkie zapytania
return Promise.all( elems );
}
};

+ 115
- 0
schema/sample/menus.js View File

@@ -0,0 +1,115 @@
/*
* This file is part of Pulsar CMS
* Copyright (c) by sobiemir <sobiemir@aculo.pl>
* ___ __
* / _ \__ __/ /__ ___ _____
* / ___/ // / (_-</ _ `/ __/
* /_/ \_,_/_/___/\_,_/_/
*
* This source file is subject to the New BSD License that is bundled
* with this package in the file LICENSE.txt.
*
* You should have received a copy of the New BSD License along with
* this program. If not, see <http://www.licenses.aculo.pl/>.
*/

const menus = [{
id: 1,
id_language: 1,
private: false,
online: true,
order: 1,
name: "Menu główne"
}, {
id: 2,
id_language: 1,
private: true,
online: true,
order: 2,
name: "Menu systemowe"
}, {
id: 1,
id_language: 2,
private: false,
online: true,
order: 2,
name: "Main menu"
}, {
id: 2,
id_language: 2,
private: true,
online: true,
order: 1,
name: "System menu"
}, {
id: 3,
id_language: 2,
private: false,
online: false,
order: 3,
name: "Sidebar menu"
}, {
id: 3,
id_language: 3,
private: false,
online: false,
order: 1,
name: "Нижнее меню"
}, {
id: 4,
id_language: 2,
private: true,
online: false,
order: 4,
name: "Footer menu"
}];

module.exports = {
// wgrywanie danych testowych
up: (queryInterface, Sequelize) =>
{
let sql = queryInterface.QueryGenerator.selectQuery( "menu", {
limit: 1
} );
// sprawdź czy menu są już wrzucone
return queryInterface.sequelize.query( sql, {
type: Sequelize.QueryTypes.SELECT,
raw: true
// oraz czy są dostępne odpowiednie języki
} ).then( (data) => {
if( data.length > 0 )
throw "You can insert test data only to empty table."

sql = queryInterface.QueryGenerator.selectQuery( "language", {
where: {
id: [1, 2, 3, 4, 5]
}
} );
return queryInterface.sequelize.query( sql, {
type: Sequelize.QueryTypes.SELECT,
raw: true
} );
// jeżeli wszystko jest ok, wrzuć dane
} ).then( (data) => {
if( data.length != 5 )
throw "You don't have languages needed for query.";

return queryInterface.bulkInsert( "menu", menus );
} );
},

// usuwanie danych testowych
down: (queryInterface, Sequelize) =>
{
// utwórz warunki - sprawdzaj czy element zgadza się z tym wgrywanym
const elems = [];
for( const menu of menus )
elems.push( queryInterface.bulkDelete("menu", {
id: menu.id,
id_language: menu.id_language,
name: menu.name
}) );
// wykonaj wszystkie zapytania
return Promise.all( elems );
}
};

+ 71
- 0
schema/sample/users.js View File

@@ -0,0 +1,71 @@
/*
* This file is part of Pulsar CMS
* Copyright (c) by sobiemir <sobiemir@aculo.pl>
* ___ __
* / _ \__ __/ /__ ___ _____
* / ___/ // / (_-</ _ `/ __/
* /_/ \_,_/_/___/\_,_/_/
*
* This source file is subject to the New BSD License that is bundled
* with this package in the file LICENSE.txt.
*
* You should have received a copy of the New BSD License along with
* this program. If not, see <http://www.licenses.aculo.pl/>.
*/

const users = [{
id: 1,
username: "admin",
screen_name: "Mr. Admin",
email: "admin@test.site",
password: "$2y$10$N0VLcURMV2d5OGdpVk1UV.1gSpUmKuHQcAM/VLn.1cXbYAC7HeGUK",
join_date: null,
status: 1
}, {
id: 2,
username: "test",
screen_name: "Ms. Test",
email: "test@test.site",
password: "$2y$10$RDR0cXM1eWRaU3ZuM2U4aeSVmhsByokNIIHBTD1JGgpVaW09BE.4q",
join_date: null,
status: 0
}];

module.exports = {
// wgrywanie danych testowych
up: (queryInterface, Sequelize) =>
{
let sql = queryInterface.QueryGenerator.selectQuery( "user", {
limit: 1
} );
return queryInterface.sequelize.query( sql, {
type: Sequelize.QueryTypes.SELECT,
raw: true
} ).then( (data) => {
if( data.length > 0 )
throw "You can insert test data only to empty table."

// aktualna data dołączenia użytkownika
for( const user of users )
user.join_date = queryInterface.sequelize.fn( "NOW" );

return queryInterface.bulkInsert( "user", users );
} );
},

// usuwanie danych testowych
down: (queryInterface, Sequelize) =>
{
// utwórz warunki - sprawdzaj czy element zgadza się z tym wgrywanym
const elems = [];
for( const user of users )
elems.push( queryInterface.bulkDelete("user", {
id: user.id,
username: user.username,
screen_name: user.screen_name,
email: user.email
}) );
// wykonaj wszystkie zapytania
return Promise.all( elems );
}
};

+ 7
- 23
schema/schema.sql View File

@@ -13,21 +13,6 @@
-- this program. If not, see <http://www.licenses.aculo.pl/>.
--

DROP FUNCTION IF EXISTS UUID2BIN;

CREATE FUNCTION UUID2BIN(s CHAR(36))
RETURNS binary(16)
DETERMINISTIC

RETURN UNHEX(CONCAT(
SUBSTRING(s,7,2),SUBSTRING(s,5,2),SUBSTRING(s,3,2),SUBSTRING(s,1,2),
SUBSTRING(s,12,2),SUBSTRING(s,10,2),
SUBSTRING(s,17,2),SUBSTRING(s,15,2),
SUBSTRING(s,20,4),
SUBSTRING(s,25,12)
)
);

DROP TABLE IF EXISTS `menu`;
DROP TABLE IF EXISTS `language`;
DROP TABLE IF EXISTS `user`;
@@ -51,9 +36,9 @@ DROP TABLE IF EXISTS `user`;
-- =============================================================================
CREATE TABLE `language`
(
`id` BINARY(16) NOT NULL,
`frontend` BOOLEAN NOT NULL DEFAULT 0,
`backend` BOOLEAN NOT NULL DEFAULT 0,
`id` INTEGER NOT NULL AUTO_INCREMENT,
`frontend` BOOLEAN NOT NULL DEFAULT TRUE,
`backend` BOOLEAN NOT NULL DEFAULT TRUE,
`direction` CHAR(1) NOT NULL DEFAULT 'L',
`order` INTEGER NOT NULL DEFAULT 0,
`code` VARCHAR(20) NOT NULL DEFAULT "pl",
@@ -80,8 +65,8 @@ CREATE TABLE `language`
-- =============================================================================
CREATE TABLE `menu`
(
`id` BINARY(16) NOT NULL,
`id_language` BINARY(16) NOT NULL,
`id` INTEGER NOT NULL AUTO_INCREMENT,
`id_language` INTEGER NOT NULL,
`private` BOOLEAN NOT NULL DEFAULT 1,
`online` BOOLEAN NOT NULL DEFAULT 1,
`order` INTEGER NOT NULL DEFAULT 0,
@@ -108,12 +93,12 @@ CREATE TABLE `menu`
-- =============================================================================
CREATE TABLE `user`
(
`id` BINARY(16) NOT NULL,
`id` INTEGER NOT NULL AUTO_INCREMENT,
`username` VARCHAR(50) NOT NULL,
`screen_name` VARCHAR(70) NOT NULL,
`email` VARCHAR(100) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`join_date` DATETIME NOT NULL DEFAULT NOW(),
`join_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`status` INTEGER NOT NULL DEFAULT 0,

PRIMARY KEY (`id`),
@@ -121,4 +106,3 @@ CREATE TABLE `user`
UNIQUE KEY (`screen_name`),
UNIQUE KEY (`email`)
);


+ 14
- 45
schema/test.sql View File

@@ -16,61 +16,30 @@
-- UŻYTKOWNICY
-- =============================================================================
INSERT INTO `user` VALUES
(UUID2BIN("e123ef97-50be-4641-a3a0-b36bc41e1894"),
"admin", "Mr. Admin", "admin@test.site",
(1, "admin", "Mr. Admin", "admin@test.site",
"$2y$10$N0VLcURMV2d5OGdpVk1UV.1gSpUmKuHQcAM/VLn.1cXbYAC7HeGUK",
NOW(), 1),

(UUID2BIN("5e77bedd-0557-4093-9ea9-593d1192641d"),
"test", "Ms. Test", "test@test.site",
(2, "test", "Ms. Test", "test@test.site",
"$2y$10$RDR0cXM1eWRaU3ZuM2U4aeSVmhsByokNIIHBTD1JGgpVaW09BE.4q",
NOW(), 0);

-- JĘZYKI
-- =============================================================================
INSERT INTO `language` VALUES
(UUID2BIN("9e76c39b-fb16-474d-b4aa-cf4c1ff7d441"),
TRUE, TRUE, 1, 1, "pl", "Polski"),

(UUID2BIN("6f2b56fc-6ad5-4bbd-abac-646ed79b5cd0"),
TRUE, TRUE, 1, 2, "en", "English"),

(UUID2BIN("5ecc2846-0b64-4595-8328-dd47cc5a5e2e"),
TRUE, FALSE, 1, 3, "ru", "Русский"),

(UUID2BIN("78bc6fee-679a-4782-abf2-ad1e8dd20860"),
FALSE, TRUE, 1, 4, "de", "Deutsch"),

(UUID2BIN("0b8b117e-a10a-463f-8155-d1a00196e537"),
FALSE, FALSE, 1, 5, "ko", "한국어");
(1, TRUE, TRUE, 'L', 1, "pl", "Polski"),
(2, TRUE, TRUE, 'L', 2, "en", "English"),
(3, TRUE, FALSE, 'L', 3, "ru", "Русский"),
(4, FALSE, TRUE, 'L', 4, "de", "Deutsch"),
(5, FALSE, FALSE, 'L', 5, "ko", "한국어");

-- MENU
-- =============================================================================
INSERT INTO `menu` VALUES
(UUID2BIN("634aa9bd-d1db-436f-b647-542d815717c1"),
UUID2BIN("9e76c39b-fb16-474d-b4aa-cf4c1ff7d441"),
FALSE, TRUE, 1, "Menu główne"),

(UUID2BIN("0c0ba94e-0c7a-4831-b06b-914c47deb3a6"),
UUID2BIN("9e76c39b-fb16-474d-b4aa-cf4c1ff7d441"),
TRUE, TRUE, 2, "Menu systemowe"),

(UUID2BIN("634aa9bd-d1db-436f-b647-542d815717c1"),
UUID2BIN("6f2b56fc-6ad5-4bbd-abac-646ed79b5cd0"),
FALSE, TRUE, 1, "Main menu"),

(UUID2BIN("0c0ba94e-0c7a-4831-b06b-914c47deb3a6"),
UUID2BIN("6f2b56fc-6ad5-4bbd-abac-646ed79b5cd0"),
TRUE, TRUE, 2, "System menu"),

(UUID2BIN("7dc7f931-4e5a-474f-a289-dd794b34f099"),
UUID2BIN("6f2b56fc-6ad5-4bbd-abac-646ed79b5cd0"),
FALSE, FALSE, 3, "Sidebar menu"),

(UUID2BIN("e98e4071-9b11-41a8-837f-a797b80bb72d"),
UUID2BIN("5ecc2846-0b64-4595-8328-dd47cc5a5e2e"),
FALSE, FALSE, 1, "Нижнее меню"),

(UUID2BIN("e98e4071-9b11-41a8-837f-a797b80bb72d"),
UUID2BIN("6f2b56fc-6ad5-4bbd-abac-646ed79b5cd0"),
TRUE, FALSE, 4, "Footer menu");
(1, 1, FALSE, TRUE, 1, "Menu główne"),
(2, 1, TRUE, TRUE, 2, "Menu systemowe"),
(1, 2, FALSE, TRUE, 1, "Main menu"),
(2, 2, TRUE, TRUE, 2, "System menu"),
(3, 2, FALSE, FALSE, 3, "Sidebar menu"),
(3, 3, FALSE, FALSE, 1, "Нижнее меню"),
(4, 2, TRUE, FALSE, 4, "Footer menu");

+ 15
- 15
tsconfig.static.json View File

@@ -1,16 +1,16 @@
{
"compilerOptions": {
"module": "AMD",
"target": "ES5",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "public/themes/pluto/js",
"outFile": "public/themes/pluto/js/app.static.js"
},
"files": [
"public/themes/pluto/ts.static/Application.ts",
"public/themes/pluto/ts.static/Prototypes.ts"
]
}
"compilerOptions": {
"module": "AMD",
"target": "ES5",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"outDir": "public/themes/pluto/js",
"outFile": "public/themes/pluto/js/app.static.js"
},
"files": [
"public/themes/pluto/ts.static/Application.ts",
"public/themes/pluto/ts.static/Prototypes.ts"
]
}

Loading…
Cancel
Save