Add initial version of dijkstra backend cloudron image

This commit is contained in:
2020-10-12 11:27:15 +02:00
commit 4f5db9ab26
4209 changed files with 448228 additions and 0 deletions

7
data/dbConfig.js Normal file
View File

@@ -0,0 +1,7 @@
const knex = require('knex');
const config = require('../knexfile');
const environment = 'development';
module.exports = knex(config[environment]);

View File

@@ -0,0 +1,13 @@
exports.up = function(knex, Promise) {
return knex.schema.createTable('countries', function(countries) {
countries.increments();
countries
.string('name', 128)
.notNullable()
.unique();
});
};
exports.down = function(knex, Promise) {
return knex.schema.dropTableIfExists('countries');
};

View File

@@ -0,0 +1,20 @@
exports.up = function(knex) {
return knex.schema.createTable('cities', function(cities) {
cities.increments();
cities.string('name', 128).notNullable();
cities
.integer('country_id')
.unsigned()
.notNullable()
.references('id')
.inTable('countries')
.onDelete('CASCADE')
.onUpdate('CASCADE');
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('cities');
};

View File

@@ -0,0 +1,32 @@
exports.up = function(knex) {
return knex.schema.createTable('roads', function(roads) {
roads.increments();
roads
.integer('start_city_id')
.unsigned()
.notNullable()
.references('id')
.inTable('cities')
.onDelete('CASCADE')
.onUpdate('CASCADE');
roads
.integer('end_city_id')
.unsigned()
.notNullable()
.references('id')
.inTable('cities')
.onDelete('CASCADE')
.onUpdate('CASCADE');
roads
.integer('distance')
.unsigned()
.notNullable()
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('roads');
};

View File

@@ -0,0 +1,12 @@
exports.seed = function(knex) {
return knex('countries').truncate()
.then(function () {
return knex('countries').insert([
{
id: 1,
name: 'Belgium',
}
]);
});
};

58
data/seeds/02-cities.js Normal file
View File

@@ -0,0 +1,58 @@
exports.seed = function (knex) {
return knex('cities')
.truncate()
.then(function () {
return knex('cities').insert([
{
id: 1,
name: 'bruges',
country_id: 1,
},
{
id: 2,
name: 'antwerp',
country_id: 1,
},
{
id: 3,
name: 'ghent',
country_id: 1,
},
{
id: 4,
name: 'mechelen',
country_id: 1,
},
{
id: 5,
name: 'brussels',
country_id: 1,
},
{
id: 6,
name: 'mons',
country_id: 1,
},
{
id: 7,
name: 'namur',
country_id: 1,
},
{
id: 8,
name: 'liege',
country_id: 1,
},
{
id: 9,
name: 'arlon',
country_id: 1,
},
{
id: 10,
name: 'tournai',
country_id: 1,
},
]);
});
};

92
data/seeds/03-roads.js Normal file
View File

@@ -0,0 +1,92 @@
exports.seed = function (knex) {
return knex('roads')
.truncate()
.then(function () {
return knex('roads').insert([
{
id: 1,
start_city_id: 1,
end_city_id: 3,
distance: 40,
},
{
id: 2,
start_city_id: 3,
end_city_id: 10,
distance: 60,
},
{
id: 3,
start_city_id: 10,
end_city_id: 5,
distance: 70,
},
{
id: 4,
start_city_id: 3,
end_city_id: 5,
distance: 50,
},
{
id: 5,
start_city_id: 3,
end_city_id: 2,
distance: 50,
},
{
id: 6,
start_city_id: 2,
end_city_id: 4,
distance: 20,
},
{
id: 7,
start_city_id: 4,
end_city_id: 5,
distance: 20,
},
{
id: 8,
start_city_id: 5,
end_city_id: 6,
distance: 50,
},
{
id: 9,
start_city_id: 6,
end_city_id: 7,
distance: 60,
},
{
id: 10,
start_city_id: 6,
end_city_id: 10,
distance: 40,
},
{
id: 11,
start_city_id: 7,
end_city_id: 9,
distance: 110,
},
{
id: 12,
start_city_id: 9,
end_city_id: 7,
distance: 110,
},
{
id: 13,
start_city_id: 8,
end_city_id: 7,
distance: 50,
},
{
id: 14,
start_city_id: 8,
end_city_id: 5,
distance: 90,
},
]);
});
};