Skip to content

Commit

Permalink
feat: PRO-2395 sequelize repository updates and conflict resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
kanthgithub committed Jun 12, 2024
1 parent 72d9fc1 commit 8ea0217
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 306 deletions.
16 changes: 8 additions & 8 deletions admin_frontend/src/components/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ const Dashboard = () => {
setConfig(dataJson);
setEdittedConfig(dataJson);
let buffer;
if (data.COINGECKO_IDS && data.COINGECKO_IDS !== "") {
buffer = Buffer.from(data.COINGECKO_IDS, "base64");
if (data.coingeckoIds && data.coingeckoIds !== "") {
buffer = Buffer.from(data.coingeckoIds, "base64");
const coingeckoIds = JSON.parse(buffer.toString());
setCoingeckoIds(coingeckoIds);
}
if (
data.DEPLOYED_ERC20_PAYMASTERS &&
data.DEPLOYED_ERC20_PAYMASTERS !== ""
data.deployedErc20Paymasters &&
data.deployedErc20Paymasters !== ""
) {
buffer = Buffer.from(data.DEPLOYED_ERC20_PAYMASTERS, "base64");
buffer = Buffer.from(data.deployedErc20Paymasters, "base64");
setDeployedPaymasters(JSON.parse(buffer.toString()));
}
if (
data.CUSTOM_CHAINLINK_DEPLOYED &&
data.CUSTOM_CHAINLINK_DEPLOYED !== ""
data.customChainlinkDeployed &&
data.customChainlinkDeployed !== ""
) {
buffer = Buffer.from(data.CUSTOM_CHAINLINK_DEPLOYED, "base64");
buffer = Buffer.from(data.customChainlinkDeployed, "base64");
setCustomChainlink(JSON.parse(buffer.toString()));
}
setDisableSave(true);
Expand Down
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"sqlite3": "5.1.7-rc.0",
"ts-node": "^10.9.2",
"typescript": "^5.4.5",
"umzug": "^3.8.1",
"viem": "2.7.6"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ setTimeout(async () => {
for (const signal of ['SIGINT', 'SIGTERM']) {
process.on(signal, () =>
server.close().then((err) => {
server.sqlite.close();
server.sequelize.close();
console.log(`close application on ${signal}`);
process.exit(err ? 1 : 0);
}),
Expand Down
42 changes: 0 additions & 42 deletions backend/src/migrations/001-default.do.sql

This file was deleted.

24 changes: 0 additions & 24 deletions backend/src/migrations/002-apiKeys.do.sql

This file was deleted.

44 changes: 0 additions & 44 deletions backend/src/migrations/003-sponsorship-policy.do.sql

This file was deleted.

24 changes: 22 additions & 2 deletions backend/src/models/APIKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export class APIKey extends Model {
declare updatedAt: Date; // Added this line
}

export function initializeAPIKeyModel(sequelize: Sequelize) {
export function initializeAPIKeyModel(sequelize: Sequelize, schema: string) {

console.log('Initializing APIKey model...')

APIKey.init({
const initializedAPIKeyModel = APIKey.init({
apiKey: {
type: DataTypes.TEXT,
allowNull: false,
Expand Down Expand Up @@ -84,10 +84,30 @@ export function initializeAPIKeyModel(sequelize: Sequelize) {
allowNull: true,
field: 'INDEXER_ENDPOINT'
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
field: 'CREATED_AT'
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
field: 'UPDATED_AT'
},
}, {
tableName: 'api_keys',
sequelize, // passing the `sequelize` instance is required
//modelName: 'APIKey',
timestamps: true, // enabling timestamps
createdAt: 'createdAt', // mapping 'createdAt' to 'CREATED_AT'
updatedAt: 'updatedAt', // mapping 'updatedAt' to 'UPDATED_AT'
freezeTableName: true,
schema: schema,
});

console.log(`apiKey inited as: ${initializedAPIKeyModel}`)

console.log('APIKey model initialized.')

return initializedAPIKeyModel;
}
96 changes: 96 additions & 0 deletions backend/src/models/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Sequelize, DataTypes, Model } from 'sequelize';

export class Config extends Model {
public id!: number; // Note that the `null assertion` `!` is required in strict mode.
public deployedErc20Paymasters!: string;
public pythMainnetUrl!: string;
public pythTestnetUrl!: string;
public pythTestnetChainIds!: string;
public pythMainnetChainIds!: string;
public cronTime!: string;
public customChainlinkDeployed!: string;
public coingeckoIds!: string;
public coingeckoApiUrl!: string;
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}

const initializeConfigModel = (sequelize: Sequelize, schema: string) => {
Config.init({
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
field: 'ID'
},
deployedErc20Paymasters: {
type: DataTypes.TEXT,
allowNull: false,
field: 'DEPLOYED_ERC20_PAYMASTERS'
},
pythMainnetUrl: {
type: DataTypes.TEXT,
allowNull: false,
field: 'PYTH_MAINNET_URL'
},
pythTestnetUrl: {
type: DataTypes.TEXT,
allowNull: false,
field: 'PYTH_TESTNET_URL'
},
pythTestnetChainIds: {
type: DataTypes.TEXT,
allowNull: false,
field: 'PYTH_TESTNET_CHAIN_IDS'
},
pythMainnetChainIds: {
type: DataTypes.TEXT,
allowNull: false,
field: 'PYTH_MAINNET_CHAIN_IDS'
},
cronTime: {
type: DataTypes.TEXT,
allowNull: false,
field: 'CRON_TIME'
},
customChainlinkDeployed: {
type: DataTypes.TEXT,
allowNull: false,
field: 'CUSTOM_CHAINLINK_DEPLOYED'
},
coingeckoIds: {
type: DataTypes.TEXT,
allowNull: true,
field: 'COINGECKO_IDS'
},
coingeckoApiUrl: {
type: DataTypes.TEXT,
allowNull: true,
field: 'COINGECKO_API_URL'
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
field: 'CREATED_AT'
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
field: 'UPDATED_AT'
},
}, {
sequelize,
tableName: 'config',
modelName: 'Config',
timestamps: true,
// createdAt: 'createdAt',
// updatedAt: 'updatedAt',
freezeTableName: true,
schema: schema,
});
};

export { initializeConfigModel };
43 changes: 31 additions & 12 deletions backend/src/models/SponsorshipPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Sequelize, DataTypes, Model } from 'sequelize';

export class SponsorshipPolicy extends Model {
declare id: number;
declare walletAddress: string;
declare name: string;
declare description: string | null;
declare startDate: Date | null;
declare endDate: Date | null;
declare isPerpetual: boolean;
declare isUniversal: boolean;
declare contractRestrictions: string | null;
public id!: number;
public walletAddress!: string;
public name!: string;
public description!: string | null;
public startDate!: Date | null;
public endDate!: Date | null;
public isPerpetual!: boolean;
public isUniversal!: boolean;
public contractRestrictions!: string | null;
public readonly createdAt!: Date;
public readonly updatedAt!: Date;
}

export function initializeSponsorshipPolicyModel(sequelize: Sequelize) {
export function initializeSponsorshipPolicyModel(sequelize: Sequelize, schema: string) {
SponsorshipPolicy.init({
id: {
type: DataTypes.INTEGER,
Expand Down Expand Up @@ -65,9 +67,26 @@ export function initializeSponsorshipPolicyModel(sequelize: Sequelize) {
allowNull: true,
field: 'CONTRACT_RESTRICTIONS'
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
field: 'CREATED_AT'
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
field: 'UPDATED_AT'
},
}, {
tableName: 'sponsorship_policies',
sequelize,
timestamps: false,
tableName: 'sponsorship_policies',
modelName: 'SponsorshipPolicy',
timestamps: true,
createdAt: 'createdAt',
updatedAt: 'updatedAt',
freezeTableName: true,
schema: schema,
});
}
Loading

0 comments on commit 8ea0217

Please sign in to comment.