added import function for migration tool.
This commit is contained in:
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, body TEXT not null, emailaddress TEXT not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, body TEXT not null, emailaddress TEXT not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, vehicleId INT not null, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace CarCareTracker.External.Implementations
|
||||
try
|
||||
{
|
||||
string cmd = $"SELECT data FROM app.{tableName} WHERE id = @id";
|
||||
var result = new UserConfigData();
|
||||
UserConfigData result = null;
|
||||
using (var ctext = new NpgsqlCommand(cmd, pgDataSource))
|
||||
{
|
||||
ctext.Parameters.AddWithValue("id", userId);
|
||||
@@ -45,7 +45,6 @@ namespace CarCareTracker.External.Implementations
|
||||
result = userConfig;
|
||||
}
|
||||
}
|
||||
if (result.UserConfig == null) { return null; }
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -59,7 +58,7 @@ namespace CarCareTracker.External.Implementations
|
||||
var existingRecord = GetUserConfig(userConfigData.Id);
|
||||
try
|
||||
{
|
||||
if (existingRecord == null || existingRecord.Id == default)
|
||||
if (existingRecord == null)
|
||||
{
|
||||
string cmd = $"INSERT INTO app.{tableName} (id, data) VALUES(@id, CAST(@data AS jsonb))";
|
||||
using (var ctext = new NpgsqlCommand(cmd, pgDataSource))
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, username TEXT not null, emailaddress TEXT not null, password TEXT not null, isadmin BOOLEAN)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, username TEXT not null, emailaddress TEXT not null, password TEXT not null, isadmin BOOLEAN)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CarCareTracker.External.Implementations
|
||||
{
|
||||
pgDataSource.Open();
|
||||
//create table if not exist.
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED ALWAYS AS IDENTITY primary key, data jsonb not null)";
|
||||
string initCMD = $"CREATE TABLE IF NOT EXISTS app.{tableName} (id INT GENERATED BY DEFAULT AS IDENTITY primary key, data jsonb not null)";
|
||||
using (var ctext = new NpgsqlCommand(initCMD, pgDataSource))
|
||||
{
|
||||
ctext.ExecuteNonQuery();
|
||||
|
||||
Reference in New Issue
Block a user