PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "migrations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "timestamp" bigint NOT NULL, "name" varchar NOT NULL);
INSERT INTO migrations VALUES(1,1588102412422,'InitialMigration1588102412422');
INSERT INTO migrations VALUES(2,1592445003908,'WebhookModel1592445003908');
INSERT INTO migrations VALUES(3,1594825041918,'CreateIndexStoppedAt1594825041918');
INSERT INTO migrations VALUES(4,1607431743769,'MakeStoppedAtNullable1607431743769');
INSERT INTO migrations VALUES(5,1611071044839,'AddWebhookId1611071044839');
INSERT INTO migrations VALUES(6,1617213344594,'CreateTagEntity1617213344594');
INSERT INTO migrations VALUES(7,1620821879465,'UniqueWorkflowNames1620821879465');
INSERT INTO migrations VALUES(8,1621707690587,'AddWaitColumn1621707690587');
INSERT INTO migrations VALUES(9,1630330987096,'UpdateWorkflowCredentials1630330987096');
INSERT INTO migrations VALUES(10,1644421939510,'AddExecutionEntityIndexes1644421939510');
INSERT INTO migrations VALUES(11,1646992772331,'CreateUserManagement1646992772331');
INSERT INTO migrations VALUES(12,1648740597343,'LowerCaseUserEmail1648740597343');
INSERT INTO migrations VALUES(13,1652254514001,'CommunityNodes1652254514001');
INSERT INTO migrations VALUES(14,1652367743993,'AddUserSettings1652367743993');
INSERT INTO migrations VALUES(15,1652905585850,'AddAPIKeyColumn1652905585850');
INSERT INTO migrations VALUES(16,1654089251344,'IntroducePinData1654089251344');
INSERT INTO migrations VALUES(17,1658930531669,'AddNodeIds1658930531669');
INSERT INTO migrations VALUES(18,1659888469333,'AddJsonKeyPinData1659888469333');
INSERT INTO migrations VALUES(19,1660062385367,'CreateCredentialsUserRole1660062385367');
INSERT INTO migrations VALUES(20,1663755770892,'CreateWorkflowsEditorRole1663755770892');
INSERT INTO migrations VALUES(21,1664196174000,'WorkflowStatistics1664196174000');
INSERT INTO migrations VALUES(22,1665484192211,'CreateCredentialUsageTable1665484192211');
INSERT INTO migrations VALUES(23,1665754637024,'RemoveCredentialUsageTable1665754637024');
INSERT INTO migrations VALUES(24,1669739707124,'AddWorkflowVersionIdColumn1669739707124');
INSERT INTO migrations VALUES(25,1669823906993,'AddTriggerCountColumn1669823906993');
INSERT INTO migrations VALUES(26,1671535397530,'MessageEventBusDestinations1671535397530');
INSERT INTO migrations VALUES(27,1671726148419,'RemoveWorkflowDataLoadedFlag1671726148419');
INSERT INTO migrations VALUES(28,1673268682475,'DeleteExecutionsWithWorkflows1673268682475');
INSERT INTO migrations VALUES(29,1674138566000,'AddStatusToExecutions1674138566000');
INSERT INTO migrations VALUES(30,1674509946020,'CreateLdapEntities1674509946020');
INSERT INTO migrations VALUES(31,1675940580449,'PurgeInvalidWorkflowConnections1675940580449');
INSERT INTO migrations VALUES(32,1676996103000,'MigrateExecutionStatus1676996103000');
INSERT INTO migrations VALUES(33,1677237073720,'UpdateRunningExecutionStatus1677237073720');
INSERT INTO migrations VALUES(34,1677501636752,'CreateVariables1677501636752');
INSERT INTO migrations VALUES(35,1679416281777,'CreateExecutionMetadataTable1679416281777');
INSERT INTO migrations VALUES(36,1681134145996,'AddUserActivatedProperty1681134145996');
INSERT INTO migrations VALUES(37,1681134145997,'RemoveSkipOwnerSetup1681134145997');
INSERT INTO migrations VALUES(38,1690000000002,'MigrateIntegerKeysToString1690000000002');
INSERT INTO migrations VALUES(39,1690000000010,'SeparateExecutionData1690000000010');
INSERT INTO migrations VALUES(40,1690000000020,'FixMissingIndicesFromStringIdMigration1690000000020');
INSERT INTO migrations VALUES(41,1690000000030,'RemoveResetPasswordColumns1690000000030');
INSERT INTO migrations VALUES(42,1690000000030,'AddMfaColumns1690000000030');
INSERT INTO migrations VALUES(43,1691088862123,'CreateWorkflowNameIndex1691088862123');
INSERT INTO migrations VALUES(44,1692967111175,'CreateWorkflowHistoryTable1692967111175');
INSERT INTO migrations VALUES(45,1693491613982,'ExecutionSoftDelete1693491613982');
INSERT INTO migrations VALUES(46,1693554410387,'DisallowOrphanExecutions1693554410387');
INSERT INTO migrations VALUES(47,1695128658538,'AddWorkflowMetadata1695128658538');
INSERT INTO migrations VALUES(48,1695829275184,'ModifyWorkflowHistoryNodesAndConnections1695829275184');
INSERT INTO migrations VALUES(49,1700571993961,'AddGlobalAdminRole1700571993961');
INSERT INTO migrations VALUES(50,1705429061930,'DropRoleMapping1705429061930');
INSERT INTO migrations VALUES(51,1711018413374,'RemoveFailedExecutionStatus1711018413374');
INSERT INTO migrations VALUES(52,1711390882123,'MoveSshKeysToDatabase1711390882123');
INSERT INTO migrations VALUES(53,1712044305787,'RemoveNodesAccess1712044305787');
INSERT INTO migrations VALUES(54,1714133768519,'CreateProject1714133768519');
INSERT INTO migrations VALUES(55,1714133768521,'MakeExecutionStatusNonNullable1714133768521');
INSERT INTO migrations VALUES(56,1717498465931,'AddActivatedAtUserSetting1717498465931');
INSERT INTO migrations VALUES(57,1720101653148,'AddConstraintToExecutionMetadata1720101653148');
INSERT INTO migrations VALUES(58,1723627610222,'CreateInvalidAuthTokenTable1723627610222');
INSERT INTO migrations VALUES(59,1723796243146,'RefactorExecutionIndices1723796243146');
INSERT INTO migrations VALUES(60,1724753530828,'CreateAnnotationTables1724753530828');
INSERT INTO migrations VALUES(61,1724951148974,'AddApiKeysTable1724951148974');
INSERT INTO migrations VALUES(62,1726606152711,'CreateProcessedDataTable1726606152711');
INSERT INTO migrations VALUES(63,1727427440136,'SeparateExecutionCreationFromStart1727427440136');
INSERT INTO migrations VALUES(64,1728659839644,'AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644');
INSERT INTO migrations VALUES(65,1729607673464,'UpdateProcessedDataValueColumnToText1729607673464');
INSERT INTO migrations VALUES(66,1729607673469,'AddProjectIcons1729607673469');
INSERT INTO migrations VALUES(67,1730386903556,'CreateTestDefinitionTable1730386903556');
INSERT INTO migrations VALUES(68,1731404028106,'AddDescriptionToTestDefinition1731404028106');
INSERT INTO migrations VALUES(69,1731582748663,'MigrateTestDefinitionKeyToString1731582748663');
INSERT INTO migrations VALUES(70,1732271325258,'CreateTestMetricTable1732271325258');
INSERT INTO migrations VALUES(71,1732549866705,'CreateTestRun1732549866705');
INSERT INTO migrations VALUES(72,1733133775640,'AddMockedNodesColumnToTestDefinition1733133775640');
INSERT INTO migrations VALUES(73,1734479635324,'AddManagedColumnToCredentialsTable1734479635324');
INSERT INTO migrations VALUES(74,1736172058779,'AddStatsColumnsToTestRun1736172058779');
INSERT INTO migrations VALUES(75,1736947513045,'CreateTestCaseExecutionTable1736947513045');
INSERT INTO migrations VALUES(76,1737715421462,'AddErrorColumnsToTestRuns1737715421462');
INSERT INTO migrations VALUES(77,1738709609940,'CreateFolderTable1738709609940');
INSERT INTO migrations VALUES(78,1739549398681,'CreateAnalyticsTables1739549398681');
INSERT INTO migrations VALUES(79,1740445074052,'UpdateParentFolderIdColumn1740445074052');
INSERT INTO migrations VALUES(80,1741167584277,'RenameAnalyticsToInsights1741167584277');
INSERT INTO migrations VALUES(81,1742918400000,'AddScopesColumnToApiKeys1742918400000');
INSERT INTO migrations VALUES(82,1745322634000,'ClearEvaluation1745322634000');
INSERT INTO migrations VALUES(83,1745587087521,'AddWorkflowStatisticsRootCount1745587087521');
INSERT INTO migrations VALUES(84,1745934666076,'AddWorkflowArchivedColumn1745934666076');
INSERT INTO migrations VALUES(85,1745934666077,'DropRoleTable1745934666077');
INSERT INTO migrations VALUES(86,1747824239000,'AddProjectDescriptionColumn1747824239000');
INSERT INTO migrations VALUES(87,1750252139166,'AddLastActiveAtColumnToUser1750252139166');
INSERT INTO migrations VALUES(88,1750252139166,'AddScopeTables1750252139166');
INSERT INTO migrations VALUES(89,1750252139167,'AddRolesTables1750252139167');
INSERT INTO migrations VALUES(90,1750252139168,'LinkRoleToUserTable1750252139168');
INSERT INTO migrations VALUES(91,1750252139170,'RemoveOldRoleColumn1750252139170');
INSERT INTO migrations VALUES(92,1752669793000,'AddInputsOutputsToTestCaseExecution1752669793000');
INSERT INTO migrations VALUES(93,1753953244168,'LinkRoleToProjectRelationTable1753953244168');
INSERT INTO migrations VALUES(94,1754475614601,'CreateDataStoreTables1754475614601');
INSERT INTO migrations VALUES(95,1754475614602,'ReplaceDataStoreTablesWithDataTables1754475614602');
INSERT INTO migrations VALUES(96,1756906557570,'AddTimestampsToRoleAndRoleIndexes1756906557570');
INSERT INTO migrations VALUES(97,1758731786132,'AddAudienceColumnToApiKeys1758731786132');
INSERT INTO migrations VALUES(98,1758794506893,'AddProjectIdToVariableTable1758794506893');
INSERT INTO migrations VALUES(99,1759399811000,'ChangeValueTypesForInsights1759399811000');
INSERT INTO migrations VALUES(100,1760019379982,'CreateChatHubTables1760019379982');
INSERT INTO migrations VALUES(101,1760020000000,'CreateChatHubAgentTable1760020000000');
INSERT INTO migrations VALUES(102,1760020838000,'UniqueRoleNames1760020838000');
INSERT INTO migrations VALUES(103,1760116750277,'CreateOAuthEntities1760116750277');
INSERT INTO migrations VALUES(104,1760314000000,'CreateWorkflowDependencyTable1760314000000');
INSERT INTO migrations VALUES(105,1760965142113,'DropUnusedChatHubColumns1760965142113');
INSERT INTO migrations VALUES(106,1761047826451,'AddWorkflowVersionColumn1761047826451');
INSERT INTO migrations VALUES(107,1761655473000,'ChangeDependencyInfoToJson1761655473000');
INSERT INTO migrations VALUES(108,1761773155024,'AddAttachmentsToChatHubMessages1761773155024');
INSERT INTO migrations VALUES(109,1761830340990,'AddToolsColumnToChatHubTables1761830340990');
INSERT INTO migrations VALUES(110,1762177736257,'AddWorkflowDescriptionColumn1762177736257');
INSERT INTO migrations VALUES(111,1762763704614,'BackfillMissingWorkflowHistoryRecords1762763704614');
INSERT INTO migrations VALUES(112,1762771954619,'AddIsGlobalColumnToCredentialsTable1762771954619');
INSERT INTO migrations VALUES(113,1762847206508,'AddWorkflowHistoryAutoSaveFields1762847206508');
INSERT INTO migrations VALUES(114,1763047800000,'AddActiveVersionIdColumn1763047800000');
INSERT INTO migrations VALUES(115,1763048000000,'ActivateExecuteWorkflowTriggerWorkflows1763048000000');
INSERT INTO migrations VALUES(116,1763572724000,'ChangeOAuthStateColumnToUnboundedVarchar1763572724000');
INSERT INTO migrations VALUES(117,1763716655000,'CreateBinaryDataTable1763716655000');
INSERT INTO migrations VALUES(118,1764167920585,'CreateWorkflowPublishHistoryTable1764167920585');
INSERT INTO migrations VALUES(119,1764276827837,'AddCreatorIdToProjectTable1764276827837');
INSERT INTO migrations VALUES(120,1764682447000,'CreateDynamicCredentialResolverTable1764682447000');
INSERT INTO migrations VALUES(121,1764689388394,'AddDynamicCredentialEntryTable1764689388394');
INSERT INTO migrations VALUES(122,1764689448000,'AddResolvableFieldsToCredentials1764689448000');
INSERT INTO migrations VALUES(123,1765448186933,'BackfillMissingWorkflowHistoryRecords1765448186933');
INSERT INTO migrations VALUES(124,1765788427674,'AddIconToAgentTable1765788427674');
INSERT INTO migrations VALUES(125,1765886667897,'AddAgentIdForeignKeys1765886667897');
INSERT INTO migrations VALUES(126,1765892199653,'AddWorkflowVersionIdToExecutionData1765892199653');
INSERT INTO migrations VALUES(127,1766064542000,'AddWorkflowPublishScopeToProjectRoles1766064542000');
INSERT INTO migrations VALUES(128,1766068346315,'AddChatMessageIndices1766068346315');
INSERT INTO migrations VALUES(129,1767018516000,'ChangeWorkflowStatisticsFKToNoAction1767018516000');
INSERT INTO migrations VALUES(130,1768402473068,'ExpandModelColumnLength1768402473068');
INSERT INTO migrations VALUES(131,1768557000000,'AddStoredAtToExecutionEntity1768557000000');
INSERT INTO migrations VALUES(132,1768901721000,'AddDynamicCredentialUserEntryTable1768901721000');
INSERT INTO migrations VALUES(133,1769000000000,'AddPublishedVersionIdToWorkflowDependency1769000000000');
INSERT INTO migrations VALUES(134,1769433700000,'CreateSecretsProviderConnectionTables1769433700000');
INSERT INTO migrations VALUES(135,1769698710000,'CreateWorkflowPublishedVersionTable1769698710000');
INSERT INTO migrations VALUES(136,1769784356000,'ExpandSubjectIDColumnLength1769784356000');
INSERT INTO migrations VALUES(137,1769900001000,'AddWorkflowUnpublishScopeToCustomRoles1769900001000');
INSERT INTO migrations VALUES(138,1770000000000,'CreateChatHubToolsTable1770000000000');
INSERT INTO migrations VALUES(139,1770000000000,'ExpandProviderIdColumnLength1770000000000');
INSERT INTO migrations VALUES(140,1770220686000,'CreateWorkflowBuilderSessionTable1770220686000');
INSERT INTO migrations VALUES(141,1771417407753,'AddScalingFieldsToTestRun1771417407753');
INSERT INTO migrations VALUES(142,1771500000000,'MigrateExternalSecretsToEntityStorage1771500000000');
INSERT INTO migrations VALUES(143,1771500000001,'AddUnshareScopeToCustomRoles1771500000001');
INSERT INTO migrations VALUES(144,1771500000002,'AddFilesColumnToChatHubAgents1771500000002');
INSERT INTO migrations VALUES(145,1772000000000,'AddSuggestedPromptsToAgentTable1772000000000');
INSERT INTO migrations VALUES(146,1772619247761,'AddRoleColumnToProjectSecretsProviderAccess1772619247761');
INSERT INTO migrations VALUES(147,1772619247762,'ChangeWorkflowPublishedVersionFKsToRestrict1772619247762');
INSERT INTO migrations VALUES(148,1772700000000,'AddTypeToChatHubSessions1772700000000');
CREATE TABLE IF NOT EXISTS "settings" ("key"	TEXT NOT NULL,"value"	TEXT NOT NULL DEFAULT '',"loadOnStartup"	boolean NOT NULL default false,PRIMARY KEY("key"));
INSERT INTO settings VALUES('userManagement.isInstanceOwnerSetUp','true',1);
INSERT INTO settings VALUES('ui.banners.dismissed','["V1"]',1);
INSERT INTO settings VALUES('features.ldap','{"loginEnabled":false,"loginLabel":"","connectionUrl":"","allowUnauthorizedCerts":false,"connectionSecurity":"none","connectionPort":389,"baseDn":"","bindingAdminDn":"","bindingAdminPassword":"","firstNameAttribute":"","lastNameAttribute":"","emailAttribute":"","loginIdAttribute":"","ldapIdAttribute":"","userFilter":"","synchronizationEnabled":false,"synchronizationInterval":60,"searchPageSize":0,"searchTimeout":60,"enforceEmailUniqueness":true}',1);
INSERT INTO settings VALUES('license.cert','eyJsaWNlbnNlS2V5IjoiLS0tLS1CRUdJTiBMSUNFTlNFIEtFWS0tLS0tXG5nNDlYRVFwbWVVWVpFcmcxTjBySGo4RitSVlRrNU52Q1RqenI4ZUtycGc0TU1wNC95dWoyOUExTVZaU2xWSThJXG5TSkREejQ4ei9BY1JjZG54YlZ0cDRYRXNON3lRVWJmZkJMampxTjdvcGNGbnY5OXoxN2NQOTZkajYxNHBLeW5xXG5YMlYrbmlVT2FYNnp6SzdxY1NNZlo3LysxVi8rRXg4d2hIYk12aXFzRzgvT01WYmVNM2lFSFZ3WXVMVkt5REpxXG50Rm1ETUpZZ2VOREZmRlEzRjlaaUJGNjVZaHk5Snd1QjB4QVE1c0FYVmVramMvbTZJQ2x2RklDSWNVTHl3bmdDXG5VczFjM0tyS0gxbTFJcUo2d3dCZFNYd3lIZmdnV1lEN0tyTllkaDdrNlVSUTZnUWxxU2w0TWU4bWZsQXU5SlErXG5CblFwb3oreGNXZjdJczNWQ3VmQU13PT18fFUyRnNkR1ZrWDEvdFAzRWl4QSthbUlJZWo4VXdVb281MjFKOTdwXG5WaGtsK1JCMjlWOVB5RDFpSDhXM2M1ajVLTDZLNEQ5WFJIVk1iMFhqWXVZUitYYUJBVSthNEtoZGtDVE1kMVNoXG4zaDBlUEdHM2VpS045Z0d0OUk3ZjlsYnJDb01XVEM2ZVljTENmNVRXRGVpaml2NExPYU9XVzhTZHhxZUhVbEo0XG5xdCtzYlNlVWZlQ0Zrd3RSUUMyZmQzamtKU3NsSGVoYnVMa1g4NTRoOWdoWGR0SllBYVFNWStWdWYrUjRmNThkXG5pL3dNN2ROcmUrNzAwS0dxNEV5eVFoNUFBbVVpeStvUXMwWDM2aXBhMGpZa2lCd0p5K2Mrc3V2bGpnTWdEWUc5XG5rN1NUeDMzblcyZjVNTmhUeTlsajVMQ1IwQjNzTnU4Wkh5ZWlrTGY4bFg0K1MvSE5kY0NHQnpKazVJcWZBd1JzXG5JVmZiT09xL3dMb29QTytZT2dXYXNQREkyWDRoZlA1UGl5bEFYMzZRSlhnRXNvUEFTbW5rTGxDWWE0Z21VQ3dpXG5Oa0dQR1dLSE1oaW1uNUhrdU9EWG5tQm1FRWtOckRUeXorWVc1RVhSQUM2dXBUZFZnYkxtdEczQ3Bjdm1ydEJoXG55UkgyVk5SQ3dLZnNEVEZIN0hVVHJXZHU3K21YbElWWnBvdjlrVGs3WGExU0dIZklaVFU0NGhRVzhnQS9NV2VYXG5raHVaYzExVDBaOWRCRzlWaVNzaEoydEpWbVoxRmx2WEZVZkJLcHZrZTA3OVZmeUxtMS9xQTVWTjMvLzZWdkZPXG5iREdoeFN1V0JCZFRMMUJwb0RGZnlBeG8rbk9WY1NBTVlTSSt5RlZkM1BjNWxNYm42R1BPZ2lqYmdlOHZRVFFkXG51MlFuRmpTWGw5SEFUZ2JybWxBdWdKcGgyQ1ZyUjI2T0JzZXpyNmRmTFJ3TittLzV2N1lxc2tuckZGcXRhclY5XG5rK2IyM25nWGpTYm53ZmFyaTJRVFpUWU9vVXhtYjRyT3o2cG4vczRTRXNHSjZFNzFNVC9PMks1MEN5TUFJSEtXXG5paDMzclBCRnVEMG5YbkJMSVRNMkY1M0IvZkJvNC8wMmUxUnRKNlREK3NLamVNZHoxRFRxN3cvd3ZZd3F3REJCXG5ua0pJSkJDVTBIVXNQZitlV0s4SmxBZUtJeUdKc2FSUUdBaktiYU9RSTZkb3dKOWV6ek9iQ3JBZGtQT3NxQmYzXG5qbnJINlBmQ0JkOGdQanRvQ3c2TC8wKy9FSUdXOEVZNkRKVTkycGFQVnFVOGpMUlFDN0JoK0tFR0hQSGtvUGNTXG5nN243ekVTbkwxa2VnWnBnWnJTVkMrRDhSRlA0b21DUEVpb3hxTnBsQVZWM1dtRGdBUTBxd3ZURDEyRXRxY0F5XG55TlplNGtQS292TWd5N214OHFXdE9mMHlxMDZNd3FRVGtOempkOHcrbFJYV2RxcnNtcE03ckc3R3pyMUVxdGNVXG40VG1sS3N1amNaL2VVMUh4d1k3OWV3Q2FzdWFRUmhmV2hmM1E5bDNRMGdVaHd1QWNKcVZ1Z2NnTW1GeWhUcjdZXG5kMkZGL1o3UnUxdHZ6N29qRE5aVXhHQVprN2h0M3NWc0l6SnBSQ1dhT3NJdWxGZmcwRFRSbklEQ0VqMllsODFtXG5NRXVYMm5tdE5TdnFpWEp6MEwxMjRYL21ETnBJZHBmWnFIbmpaak40RWNINU4vUEhPZytQUm8zek9yekJvSGM0XG4zQ1dZbTdGbUl5R1pCbVdjcUt6SlVsQXFWL0F0TVRhc2srODBseUxhalFNTklRVFlObUdXYTBHdEdGU0hjZTlwXG4wdWJRc24rSmFIZ3NqSHJRanVXd0gxZ3I4b2hpY2xYemRmMWoyZlBZYlZqaXptNU5TVGFsWVowNjB2cy9pbFBqXG5nejdKTEpYK0JXVGFvWG1sNTR2WUk4NVFzaUtaOWd6dUdsNUlURy9jM3pQa1NwcXp5aUw4WnFmZ3FMNGRveGN6XG55OWdRZWNvVW1jcnAwdTBBOVBhN241aFB2RW9ORWJDZExQejJmSkIzWjlWTlp2Y0FYbDh5eE45L1N2QWxiaUZaXG52QkQ0NVpmS2VielhHQnppb0llV0prRTMraDQvRFZWUno4ekVqNFp0T1Q4MlpjU0ZrWVAvZ1F4ZjVIcmdaRWpmXG5LTUJSMDROQkNINEQwTit6VGd5SzZWUkZSYk5QVUczc1MrM2l6SWRYM0I5OHBaNmxLc0FBMmU4SExObS9SZmZ1XG5IMEZTdTZQWE1uQitSTVJQUXFuZUJQOUh0UDBZUlJMVnZSdmJjdG4zU24rcS9JTjlsVG5tcGtBOGdoMWN1T1gyXG40Qjd5ZjNFeGw5aWlaa0ltZ0xvdGZaRGVCS0RlVjJTQmthKzRWSDVRM3BaYkJOMllmMVgzcGZjUTJOWnpiMjlWXG5EcHBzRkRGRUdkZUZPaENZeDVGU25RQkQ1TjlLWmJsNEx6VU9SR0k4SDJaVWgzSmd3KzNlbkhBaElVTS9WQlErXG5KRGppVklPRDdFdk0xek52TkcyQ0pBTWFnUkF5cGo3QnYwMXhQcWFHdEE5dEVXQXdqRHZHS3lDOHN4RG01Y1YwXG50b3NGVjNESndLeTMyNGwvVG5oekhjWFR2TFhxZHlnN0hzNkg3SHhWNnJScUZWMlpJcEJseFZmb2hKVDc3a1FCXG42djJzN252c0lTa1FOZTFCSFRiZjZDU2FpejcrMHRVbUJuM0haMHh6a3pJN0xqdG5ueUZ2ZlI0azcrdnUxNU9iXG5TOEdLUlhNUUNIdHdoY3V6YmUxOU0weDdUYWFQVkc4U1RJeDluNUVDaXlVQ2trZnFtUFVtYzZaT3BsdXlJK3hHXG5RanBjWkNEbUZjV21iSHozcWNhY2xKUkJWd3g0cFB1MTArMWUzV1FlamlBSHhGL0hqS2ZFNU13VWlFTlo3U1dQXG5rOGtpV29YQlZZeDlQMnd6enlZdytKMnNKQWREaWhtakpYUXZIUkw1YjRUOFI1clVrM1ZSNURkT2ZBTHYweWovXG5JUGROUVhvaXQxTVFqdkhuWm5nbFNkWFhXNUYvT0M5MzF0ZnR6eE9sZVZTU3hiQ3c9PXx8TW8rRHprdnNFVldOXG5KbFlkcXQrM2V3SlU4ckw3ZzhZSU4yOWFGQ2NuNnM1dVNqeTF0eThldWt3YVhSRGZ6aE1BcmVsb2s3QWpwTHd6XG5YMUhzeU50YVJzdW1YVTduMjBNMXlaekZOanY0OTB3Z3MzN3cvRnpzaFB2bmFXOTBCZHFBTjN4L083ZlBXbWxjXG40bkRGblZKWG9iZC9VanViMFlVb2RhenhUUFhVWldqanJVM3NDa3JreEtIZnpKR2o4QnlWNVFFODBlTS9jYWpNXG5Qc0hNNnQ1ODJsTi96RGV1TkR1UW00ZUNZTUhYUkxvN3VBc3Z6VU53bHFRenUrL1RRVmxPVW1oMTdLcEFLekpFXG4wQ3pJRkI5UnB2TzdwbFJiUVRmMUk5SFdFSXRHWnU5bTUwSjVhcExwWTBjbWc1RWx3R3FlMVlidEtsWlNrK2VtXG5MYXo5NnczemhRPT1cbi0tLS0tRU5EIExJQ0VOU0UgS0VZLS0tLS0iLCJ4NTA5IjoiLS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tXG5NSUlFRERDQ0FmUUNDUUNxZzJvRFQ4MHh3akFOQmdrcWhraUc5dzBCQVFVRkFEQklNUXN3Q1FZRFZRUUdFd0pFXG5SVEVQTUEwR0ExVUVDQXdHUW1WeWJHbHVNUTh3RFFZRFZRUUhEQVpDWlhKc2FXNHhGekFWQmdOVkJBTU1EbXhwXG5ZMlZ1YzJVdWJqaHVMbWx2TUI0WERUSXlNRFl5TkRBME1UQTBNRm9YRFRJek1EWXlOREEwTVRBME1Gb3dTREVMXG5NQWtHQTFVRUJoTUNSRVV4RHpBTkJnTlZCQWdNQmtKbGNteHBiakVQTUEwR0ExVUVCd3dHUW1WeWJHbHVNUmN3XG5GUVlEVlFRRERBNXNhV05sYm5ObExtNDRiaTVwYnpDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDXG5BUW9DZ2dFQkFNQk0wNVhCNDRnNXhmbUNMd2RwVVR3QVQ4K0NCa3lMS0ZzZXprRDVLLzZXaGFYL1hyc2QvUWQwXG4yMEo3d2w1V2RIVTRjVkJtRlJqVndWemtsQ0syeVlKaThtang4c1hzR3E5UTFsYlVlTUtmVjlkc2dmdWhubEFTXG50blFaZ2x1Z09uRjJGZ1JoWGIvakswdHhUb2FvK2JORTZyNGdJRXpwa3RITEJUWXZ2aXVKbXJlZjdXYlBSdDRJXG5uZDlEN2xoeWJlYnloVjdrdXpqUUEvcFBLSFRGczhNVEhaOGhZVXhSeXJwbTMrTVl6UUQrYmpBMlUxRkljdGFVXG53UVhZV2FON3QydVR3Q3Q5ekFLc21ZL1dlT2J2bDNUWk41T05MQXp5V0dDdWxtNWN3S1IzeGJsQlp6WG5CNmdzXG5Pbk4yT0FkU3RjelRWQ3ljbThwY0ZVcnl0S1NLa0dFQ0F3RUFBVEFOQmdrcWhraUc5dzBCQVFVRkFBT0NBZ0VBXG5sSjAxd2NuMXZqWFhDSHVvaTdSMERKMWxseDErZGFmcXlFcVBBMjdKdStMWG1WVkdYUW9yUzFiOHhqVXFVa2NaXG5UQndiV0ZPNXo1ZFptTnZuYnlqYXptKzZvT2cwUE1hWXhoNlRGd3NJMlBPYmM3YkZ2MmVheXdQdC8xQ3BuYzQwXG5xVU1oZnZSeC9HQ1pQQ1d6My8yUlBKV1g5alFEU0hYQ1hxOEJXK0kvM2N1TERaeVkzZkVZQkIwcDNEdlZtYWQ2XG42V0hRYVVyaU4wL0xxeVNPcC9MWmdsbC90MDI5Z1dWdDA1WmliR29LK2NWaFpFY3NMY1VJaHJqMnVGR0ZkM0ltXG5KTGcxSktKN2pLU0JVUU9kSU1EdnNGVUY3WWRNdk11ckNZQTJzT05OOENaK0k1eFFWMUtTOWV2R0hNNWZtd2dTXG5PUEZ2UHp0RENpMC8xdVc5dE9nSHBvcnVvZGFjdCtFWk5rQVRYQ3ZaaXUydy9xdEtSSkY0VTRJVEVtNWFXMGt3XG42enVDOHh5SWt0N3ZoZHM0OFV1UlNHSDlqSnJBZW1sRWl6dEdJTGhHRHF6UUdZYmxoVVFGR01iQmI3amhlTHlDXG5MSjFXT0c2MkYxc3B4Q0tCekVXNXg2cFIxelQxbWhFZ2Q0TWtMYTZ6UFRwYWNyZDk1QWd4YUdLRUxhMVJXU0ZwXG5NdmRoR2s0TnY3aG5iOHIrQnVNUkM2aWVkUE1DelhxL001MGNOOEFnOGJ3K0oxYUZvKzBFSzJoV0phN2tpRStzXG45R3ZGalNkekNGbFVQaEtra1Vaa1NvNWFPdGNRcTdKdTZrV0JoTG9GWUtncHJscDFRVkIwc0daQTZvNkR0cWphXG5HNy9SazZ2YmFZOHdzTllLMnpCWFRUOG5laDVab1JaL1BKTFV0RUV0YzdZPVxuLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLSJ9',0);
INSERT INTO settings VALUES('instance.firstProductionFailure','{"workflowId":"ioR8eFBEVaKOkjc0","projectId":"cZz5fzaW49pCUs3C","userId":"3f77e136-dc7a-4d58-8dc6-817cb2b88866","timestamp":1772773211877}',0);
CREATE TABLE IF NOT EXISTS "installed_packages" ("packageName"	char(214) NOT NULL,"installedVersion"	char(50) NOT NULL,"authorName"	char(70) NULL,"authorEmail"	char(70) NULL,"createdAt"	datetime(3) NOT NULL DEFAULT 'STRFTIME(''%Y-%m-%d %H:%M:%f'', ''NOW'')',"updatedAt"	datetime(3) NOT NULL DEFAULT 'STRFTIME(''%Y-%m-%d %H:%M:%f'', ''NOW'')',PRIMARY KEY("packageName"));
CREATE TABLE IF NOT EXISTS "installed_nodes" ("name"	char(200) NOT NULL,"type"	char(200) NOT NULL,"latestVersion"	INTEGER DEFAULT 1,"package"	char(214) NOT NULL,PRIMARY KEY("name"),FOREIGN KEY("package") REFERENCES "installed_packages"("packageName") ON DELETE CASCADE ON UPDATE CASCADE);
CREATE TABLE IF NOT EXISTS "event_destinations" ("id"	varchar(36) PRIMARY KEY NOT NULL,"destination" text NOT NULL,"createdAt"	datetime(3) NOT NULL DEFAULT 'STRFTIME(''%Y-%m-%d %H:%M:%f'', ''NOW'')',"updatedAt"	datetime(3) NOT NULL DEFAULT 'STRFTIME(''%Y-%m-%d %H:%M:%f'', ''NOW'')');
CREATE TABLE IF NOT EXISTS "auth_identity" (
				"userId" VARCHAR(36) REFERENCES "user" (id),
				"providerId" VARCHAR(64) NOT NULL,
				"providerType" VARCHAR(32) NOT NULL,
				"createdAt" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				"updatedAt" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
				PRIMARY KEY("providerId", "providerType")
			);
CREATE TABLE IF NOT EXISTS "auth_provider_sync_history" (
				"id" INTEGER PRIMARY KEY AUTOINCREMENT,
				"providerType" VARCHAR(32) NOT NULL,
				"runMode" TEXT NOT NULL,
				"status" TEXT NOT NULL,
				"startedAt" DATETIME NOT NULL,
				"endedAt" DATETIME NOT NULL,
				"scanned" INTEGER NOT NULL,
				"created" INTEGER NOT NULL,
				"updated" INTEGER NOT NULL,
				"disabled" INTEGER NOT NULL,
				"error" TEXT
			);
CREATE TABLE IF NOT EXISTS "tag_entity" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(24) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')));
CREATE TABLE IF NOT EXISTS "workflows_tags" ("workflowId" varchar(36) NOT NULL, "tagId" integer NOT NULL, CONSTRAINT "FK_workflows_tags_workflow_entity" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_workflows_tags_tag_entity" FOREIGN KEY ("tagId") REFERENCES "tag_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workflowId", "tagId"));
CREATE TABLE IF NOT EXISTS "webhook_entity" ("workflowId" varchar(36) NOT NULL, "webhookPath" varchar NOT NULL, "method" varchar NOT NULL, "node" varchar NOT NULL, "webhookId" varchar, "pathLength" integer, PRIMARY KEY ("webhookPath", "method"));
INSERT INTO webhook_entity VALUES('ioR8eFBEVaKOkjc0','create-n8n','POST','Webhook',NULL,NULL);
INSERT INTO webhook_entity VALUES('ioR8eFBEVaKOkjc0','create-n8n1111','POST','Webhook2',NULL,NULL);
CREATE TABLE IF NOT EXISTS "execution_data" (
				"executionId" int PRIMARY KEY NOT NULL,
				"workflowData" text NOT NULL,
				"data" text NOT NULL, "workflowVersionId" VARCHAR(36),
				FOREIGN KEY("executionId") REFERENCES "execution_entity" ("id") ON DELETE CASCADE
			);
INSERT INTO execution_data VALUES(1,'{"id":"ioR8eFBEVaKOkjc0","name":"Create User n8n Server","active":false,"activeVersionId":null,"nodes":[{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"curlImport":"","method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","authentication":"none","provideSslCertificates":false,"sendQuery":false,"sendHeaders":false,"sendBody":true,"contentType":"json","specifyBody":"keypair","bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{},"infoMessage":""},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"}],"connections":{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","binaryMode":"separate","availableInMCP":false},"pinData":{}}','[{"version":1,"startData":"1","resultData":"2","executionData":"3"},{"destinationNode":"4","runNodeFilter":"5"},{"runData":"6","pinData":"7","lastNodeExecuted":"8"},{"contextData":"9","nodeExecutionStack":"10","metadata":"11","waitingExecution":"12","waitingExecutionSource":"13","runtimeData":"14"},{"nodeName":"8","mode":"15"},["8"],{"HTTP Request":"16"},{},"HTTP Request",{"node:HTTP Request":"17"},[],{},{},{},{"version":1,"establishedAt":1772773211443,"source":"18","triggerNode":"19"},"inclusive",["20"],{"response":"21"},"manual",{"name":"8","type":"22"},{"startTime":1772773211447,"executionIndex":0,"source":"23","hints":"24","executionTime":494,"executionStatus":"25","data":"26"},{"body":"27"},"n8n-nodes-base.httpRequest",[],[],"success",{"main":"28"},{"message":"29"},["30"],"Workflow was started",["31"],{"json":"27","pairedItem":"32"},{"item":0}]','f2a17289-ca75-4511-a9b7-2691b7ce0fa3');
INSERT INTO execution_data VALUES(2,'{"id":"ioR8eFBEVaKOkjc0","name":"Create User n8n Server","active":true,"activeVersionId":"370acd9f-8c23-404f-be77-ec179f6ec858","isArchived":false,"createdAt":"2026-03-06T04:58:21.680Z","updatedAt":"2026-03-06T05:00:01.002Z","nodes":[{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"}],"connections":{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","binaryMode":"separate","availableInMCP":false},"staticData":{},"pinData":{}}','[{"version":1,"startData":"1","resultData":"2","executionData":"3"},{},{"error":"4","runData":"5","lastNodeExecuted":"6"},{"contextData":"7","nodeExecutionStack":"8","metadata":"9","waitingExecution":"10","waitingExecutionSource":"11","runtimeData":"12"},{"level":"13","tags":"14","timestamp":1772773211952,"context":"15","functionality":"16","name":"17","node":"18","messages":"19","message":"20","stack":"21"},{"Webhook":"22","Build Docker Command":"23","Run Docker":"24"},"Run Docker",{},["25"],{},{},{},{"version":1,"establishedAt":1772773211877,"source":"26","triggerNode":"27"},"warning",{},{"itemIndex":0},"regular","NodeOperationError",{"parameters":"28","name":"6","type":"29","position":"30","typeVersion":1,"id":"31"},[],"Command failed: docker run -d --name n8n-undefined --memory=1g --cpus=1 -v n8n_undefined:/home/node/.n8n -e N8N_HOST=n8n.undefined.inmetech.cloud -e N8N_PROTOCOL=https -e WEBHOOK_URL=https://n8n.undefined.inmetech.cloud/ -e N8N_TRUST_PROXY=true --label traefik.enable=true --label traefik.http.routers.n8n-undefined.rule=Host(`n8n.undefined.inmetech.cloud`) --label traefik.http.routers.n8n-undefined.entrypoints=websecure --label traefik.http.routers.n8n-undefined.tls.certresolver=letsencrypt --label traefik.http.services.n8n-undefined.loadbalancer.server.port=5678  docker.n8n.io/n8nio/n8n\n/bin/sh: syntax error: unexpected \"(\"\n","NodeOperationError: Command failed: docker run -d --name n8n-undefined --memory=1g --cpus=1 -v n8n_undefined:/home/node/.n8n -e N8N_HOST=n8n.undefined.inmetech.cloud -e N8N_PROTOCOL=https -e WEBHOOK_URL=https://n8n.undefined.inmetech.cloud/ -e N8N_TRUST_PROXY=true --label traefik.enable=true --label traefik.http.routers.n8n-undefined.rule=Host(`n8n.undefined.inmetech.cloud`) --label traefik.http.routers.n8n-undefined.entrypoints=websecure --label traefik.http.routers.n8n-undefined.tls.certresolver=letsencrypt --label traefik.http.services.n8n-undefined.loadbalancer.server.port=5678  docker.n8n.io/n8nio/n8n\n/bin/sh: syntax error: unexpected \"(\"\n\n    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/ExecuteCommand/ExecuteCommand.node.ts:102:12)\n    at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1043:8)\n    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1222:11)\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1665:27\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2308:11",["32"],["33"],["34"],{"node":"35","data":"36","source":"37"},"webhook",{"name":"38","type":"39"},{"executeOnce":true,"command":"40"},"n8n-nodes-base.executeCommand",[416,-144],"d049c848-745f-43ce-ad8f-2069344eb356",{"startTime":1772773211879,"executionIndex":0,"source":"41","hints":"42","executionTime":1,"executionStatus":"43","data":"44"},{"startTime":1772773211881,"executionIndex":1,"source":"45","hints":"46","executionTime":36,"executionStatus":"43","data":"47"},{"startTime":1772773211917,"executionIndex":2,"source":"48","hints":"49","executionTime":55,"executionStatus":"50","error":"51"},{"parameters":"52","name":"6","type":"29","position":"53","typeVersion":1,"id":"31"},{"main":"54"},{"main":"48"},"Webhook","n8n-nodes-base.webhook","={{$json.command}}",[],[],"success",{"main":"55"},["56"],[],{"main":"57"},["58"],[],"error",{"level":"13","tags":"14","timestamp":1772773211952,"context":"15","functionality":"16","name":"17","node":"18","messages":"19","message":"20","stack":"21"},{"executeOnce":true,"command":"40"},[416,-144],["59"],["60"],{"previousNode":"38","previousNodeOutput":0,"previousNodeRun":0},["61"],{"previousNode":"62","previousNodeOutput":0,"previousNodeRun":0},["63"],["64"],["65"],"Build Docker Command",{"json":"66","pairedItem":"67"},{"json":"68","pairedItem":"69"},{"json":"66","pairedItem":"70"},{"command":"71","url":"72"},{"item":0},{"headers":"73","params":"74","query":"75","body":"76","webhookUrl":"77","executionMode":"78"},{"item":0},{"item":0},"docker run -d --name n8n-undefined --memory=1g --cpus=1 -v n8n_undefined:/home/node/.n8n -e N8N_HOST=n8n.undefined.inmetech.cloud -e N8N_PROTOCOL=https -e WEBHOOK_URL=https://n8n.undefined.inmetech.cloud/ -e N8N_TRUST_PROXY=true --label traefik.enable=true --label traefik.http.routers.n8n-undefined.rule=Host(`n8n.undefined.inmetech.cloud`) --label traefik.http.routers.n8n-undefined.entrypoints=websecure --label traefik.http.routers.n8n-undefined.tls.certresolver=letsencrypt --label traefik.http.services.n8n-undefined.loadbalancer.server.port=5678  docker.n8n.io/n8nio/n8n","https://n8n.undefined.inmetech.cloud",{"host":"79","user-agent":"80","content-length":"81","accept":"82","accept-encoding":"83","content-type":"84","x-forwarded-for":"85","x-forwarded-host":"79","x-forwarded-port":"86","x-forwarded-proto":"87","x-forwarded-server":"88","x-real-ip":"85"},{},{},{"user_id":"89","ram":"90","cpu":"91"},"https://admin.n8n.inmetech.cloud/webhook/create-n8n","production","admin.n8n.inmetech.cloud","axios/1.13.5","42","application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","gzip, compress, deflate, br","application/json","172.18.0.1","443","https","f431cf187979","user123","1g","1"]','f2a17289-ca75-4511-a9b7-2691b7ce0fa3');
INSERT INTO execution_data VALUES(3,'{"id":"ioR8eFBEVaKOkjc0","name":"Create User n8n Server","active":false,"activeVersionId":null,"nodes":[{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"curlImport":"","method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","authentication":"none","provideSslCertificates":false,"sendQuery":false,"sendHeaders":false,"sendBody":true,"contentType":"json","specifyBody":"keypair","bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{},"infoMessage":""},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"}],"connections":{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","binaryMode":"separate","availableInMCP":false},"pinData":{"Webhook":[{"json":{"headers":{"host":"admin.n8n.inmetech.cloud","user-agent":"axios/1.13.5","content-length":"42","accept":"application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","accept-encoding":"gzip, compress, deflate, br","content-type":"application/json","x-forwarded-for":"172.18.0.1","x-forwarded-host":"admin.n8n.inmetech.cloud","x-forwarded-port":"443","x-forwarded-proto":"https","x-forwarded-server":"f431cf187979","x-real-ip":"172.18.0.1"},"params":{},"query":{},"body":{"user_id":"user123","ram":"1g","cpu":"1"},"webhookUrl":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","executionMode":"production"},"pairedItem":{"item":0}}]}}','[{"version":1,"startData":"1","resultData":"2","executionData":"3"},{"destinationNode":"4","runNodeFilter":"5"},{"error":"6","runData":"7","pinData":"8","lastNodeExecuted":"9"},{"contextData":"10","nodeExecutionStack":"11","metadata":"12","waitingExecution":"13","waitingExecutionSource":"14","runtimeData":"15"},{"nodeName":"9","mode":"16"},["17","9"],{"message":"18","stack":"19"},{"Webhook":"20","Build Docker Command":"21"},{"Webhook":"22"},"Build Docker Command",{},["23"],{},{},{},{"version":1,"establishedAt":1772773295472,"source":"24","triggerNode":"25"},"inclusive","Webhook","user_id missing [Line 4]","Error: user_id missing\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/dist/nodes/Function:4:9\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/dist/nodes/Function:36:2\n    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/vm2@3.10.5/node_modules/vm2/lib/bridge.js:672:11)\n    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/vm2@3.10.5/node_modules/vm2/lib/nodevm.js:497:23)\n    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/Function/Function.node.ts:169:21)\n    at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1043:31)\n    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1222:22)\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1665:38\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2308:11",["26"],["27"],["28"],{"node":"29","data":"30","source":"31"},"manual",{"name":"9","type":"32"},{"startTime":1772773211879,"executionIndex":0,"source":"33","hints":"34","executionTime":1,"executionStatus":"35","data":"36"},{"startTime":1772773295473,"executionIndex":1,"source":"37","hints":"38","executionTime":22,"executionStatus":"39","error":"40"},{"json":"41","pairedItem":"42"},{"parameters":"43","name":"9","type":"32","position":"44","typeVersion":1,"id":"45"},{"main":"46"},{"main":"37"},"n8n-nodes-base.function",[],[],"success",{"main":"47"},["48"],[],"error",{"message":"18","stack":"19"},{"headers":"49","params":"50","query":"51","body":"52","webhookUrl":"53","executionMode":"54"},{"item":0},{"notice":"55","functionCode":"56"},[112,-144],"7c91468e-80ea-4de5-8553-376dc01f0973",["57"],["58"],{"previousNode":"17","previousNodeOutput":0,"previousNodeRun":0},{"host":"59","user-agent":"60","content-length":"61","accept":"62","accept-encoding":"63","content-type":"64","x-forwarded-for":"65","x-forwarded-host":"59","x-forwarded-port":"66","x-forwarded-proto":"67","x-forwarded-server":"68","x-real-ip":"65"},{},{},{"user_id":"69","ram":"70","cpu":"71"},"https://admin.n8n.inmetech.cloud/webhook/create-n8n","production","","const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];",["72"],["73"],"admin.n8n.inmetech.cloud","axios/1.13.5","42","application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","gzip, compress, deflate, br","application/json","172.18.0.1","443","https","f431cf187979","user123","1g","1",{"json":"41","pairedItem":"74"},{"json":"75","pairedItem":"76"},{"item":0},{"headers":"77","params":"78","query":"79","body":"80","webhookUrl":"53","executionMode":"54"},{"item":0},{"host":"59","user-agent":"60","content-length":"61","accept":"62","accept-encoding":"63","content-type":"64","x-forwarded-for":"65","x-forwarded-host":"59","x-forwarded-port":"66","x-forwarded-proto":"67","x-forwarded-server":"68","x-real-ip":"65"},{},{},{"user_id":"69","ram":"70","cpu":"71"}]','fc3bc306-cf91-4f89-aa4b-75ee88a0be50');
INSERT INTO execution_data VALUES(4,'{"id":"ioR8eFBEVaKOkjc0","name":"Create n8n Instance","active":false,"activeVersionId":null,"nodes":[{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"curlImport":"","method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","authentication":"none","provideSslCertificates":false,"sendQuery":false,"sendHeaders":false,"sendBody":true,"contentType":"json","specifyBody":"keypair","bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{},"infoMessage":""},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"keepOnlySet":false,"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"notice":"","functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"executeOnce":true,"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"notice":"","functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"executeOnce":true,"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"executeOnce":true,"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"notice":"","functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"executeOnce":true,"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"notice":"","functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n1111","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"notice":"","functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"curlImport":"","method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","authentication":"none","provideSslCertificates":false,"sendQuery":false,"sendHeaders":false,"sendBody":true,"contentType":"json","specifyBody":"keypair","bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{},"infoMessage":""},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}],"connections":{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","binaryMode":"separate","availableInMCP":false},"pinData":{"Webhook":[{"json":{"headers":{"host":"admin.n8n.inmetech.cloud","user-agent":"axios/1.13.5","content-length":"42","accept":"application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","accept-encoding":"gzip, compress, deflate, br","content-type":"application/json","x-forwarded-for":"172.18.0.1","x-forwarded-host":"admin.n8n.inmetech.cloud","x-forwarded-port":"443","x-forwarded-proto":"https","x-forwarded-server":"f431cf187979","x-real-ip":"172.18.0.1"},"params":{},"query":{},"body":{"user_id":"user123","ram":"1g","cpu":"1"},"webhookUrl":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","executionMode":"production"},"pairedItem":{"item":0}}]}}','[{"version":1,"startData":"1","resultData":"2","executionData":"3"},{"destinationNode":"4","runNodeFilter":"5"},{"runData":"6","pinData":"7","lastNodeExecuted":"8"},{"contextData":"9","nodeExecutionStack":"10","metadata":"11","waitingExecution":"12","waitingExecutionSource":"13","runtimeData":"14"},{"nodeName":"8","mode":"15"},["8"],{"HTTP Request1":"16"},{"Webhook":"17"},"HTTP Request1",{"node:HTTP Request1":"18"},[],{},{},{},{"version":1,"establishedAt":1772773624087,"source":"19","triggerNode":"20"},"inclusive",["21"],["22"],{"response":"23"},"manual",{"name":"8","type":"24"},{"startTime":1772773624090,"executionIndex":0,"source":"25","hints":"26","executionTime":287,"executionStatus":"27","data":"28"},{"json":"29","pairedItem":"30"},{"body":"31"},"n8n-nodes-base.httpRequest",[],[],"success",{"main":"32"},{"headers":"33","params":"34","query":"35","body":"36","webhookUrl":"37","executionMode":"38"},{"item":0},{"message":"39"},["40"],{"host":"41","user-agent":"42","content-length":"43","accept":"44","accept-encoding":"45","content-type":"46","x-forwarded-for":"47","x-forwarded-host":"41","x-forwarded-port":"48","x-forwarded-proto":"49","x-forwarded-server":"50","x-real-ip":"47"},{},{},{"user_id":"51","ram":"52","cpu":"53"},"https://admin.n8n.inmetech.cloud/webhook/create-n8n","production","Workflow was started",["54"],"admin.n8n.inmetech.cloud","axios/1.13.5","42","application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","gzip, compress, deflate, br","application/json","172.18.0.1","443","https","f431cf187979","user123","1g","1",{"json":"31","pairedItem":"55"},{"item":0}]','bfa0341d-c9ac-4770-8935-19b9c2979780');
INSERT INTO execution_data VALUES(5,'{"id":"ioR8eFBEVaKOkjc0","name":"Create n8n Instance","active":true,"activeVersionId":"9d185630-6aca-46e3-b9b4-7ceb8e19d3fb","isArchived":false,"createdAt":"2026-03-06T04:58:21.680Z","updatedAt":"2026-03-06T05:06:49.520Z","nodes":[{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"curlImport":"","method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","authentication":"none","provideSslCertificates":false,"sendQuery":false,"sendHeaders":false,"sendBody":true,"contentType":"json","specifyBody":"keypair","bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{},"infoMessage":""},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"keepOnlySet":false,"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"notice":"","functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"executeOnce":true,"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"notice":"","functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"executeOnce":true,"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"executeOnce":true,"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"notice":"","functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"notice":"","functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"executeOnce":true,"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"notice":"","functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"multipleMethods":false,"httpMethod":"POST","path":"create-n8n1111","authentication":"none","responseMode":"onReceived","responseCode":200,"contentTypeNotice":"","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"notice":"","functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"executeOnce":true,"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"generalNotice":"","respondWith":"firstIncomingItem","options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"curlImport":"","method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","authentication":"none","provideSslCertificates":false,"sendQuery":false,"sendHeaders":false,"sendBody":true,"contentType":"json","specifyBody":"keypair","bodyParameters":{"parameters":[{"name":"user_id","value":"user1"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{},"infoMessage":""},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}],"connections":{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","binaryMode":"separate","availableInMCP":false},"staticData":{},"pinData":{"Webhook":[{"json":{"headers":{"host":"admin.n8n.inmetech.cloud","user-agent":"axios/1.13.5","content-length":"42","accept":"application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","accept-encoding":"gzip, compress, deflate, br","content-type":"application/json","x-forwarded-for":"172.18.0.1","x-forwarded-host":"admin.n8n.inmetech.cloud","x-forwarded-port":"443","x-forwarded-proto":"https","x-forwarded-server":"f431cf187979","x-real-ip":"172.18.0.1"},"params":{},"query":{},"body":{"user_id":"user123","ram":"1g","cpu":"1"},"webhookUrl":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","executionMode":"production"},"pairedItem":{"item":0}}]}}','[{"version":1,"startData":"1","resultData":"2","executionData":"3"},{},{"error":"4","runData":"5","lastNodeExecuted":"6"},{"contextData":"7","nodeExecutionStack":"8","metadata":"9","waitingExecution":"10","waitingExecutionSource":"11","runtimeData":"12"},{"message":"13","stack":"14"},{"Webhook2":"15","Prepare Data":"16"},"Prepare Data",{},["17"],{},{},{},{"version":1,"establishedAt":1772773624314,"source":"18","triggerNode":"19"},"user_id missing [Line 4]","Error: user_id missing\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/dist/nodes/Function:4:9\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/dist/nodes/Function:22:2\n    at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/vm2@3.10.5/node_modules/vm2/lib/bridge.js:672:11)\n    at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/vm2@3.10.5/node_modules/vm2/lib/nodevm.js:497:23)\n    at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@aws-sdk+credential-providers@3.808.0_asn1.js@5_8da18263ca0574b0db58d4fefd8173ce/node_modules/n8n-nodes-base/nodes/Function/Function.node.ts:169:21)\n    at WorkflowExecute.executeNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1043:31)\n    at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1222:22)\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:1665:38\n    at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-core@file+packages+core_@opentelemetry+api@1.9.0_@opentelemetry+exporter-trace-otlp_9f358c3eeaef0d2736f54ac9757ada43/node_modules/n8n-core/src/execution-engine/workflow-execute.ts:2308:11",["20"],["21"],{"node":"22","data":"23","source":"24"},"webhook",{"name":"25","type":"26"},{"startTime":1772773624318,"executionIndex":0,"source":"27","hints":"28","executionTime":1,"executionStatus":"29","data":"30"},{"startTime":1772773624320,"executionIndex":1,"source":"31","hints":"32","executionTime":31,"executionStatus":"33","error":"34"},{"parameters":"35","id":"36","name":"6","type":"37","position":"38","typeVersion":1},{"main":"39"},{"main":"31"},"Webhook2","n8n-nodes-base.webhook",[],[],"success",{"main":"40"},["41"],[],"error",{"message":"13","stack":"14"},{"notice":"42","functionCode":"43"},"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","n8n-nodes-base.function",[-672,1200],["44"],["45"],{"previousNode":"25","previousNodeOutput":0,"previousNodeRun":0},"","const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];",["46"],["47"],{"json":"48","pairedItem":"49"},{"json":"48","pairedItem":"50"},{"headers":"51","params":"52","query":"53","body":"54","webhookUrl":"55","executionMode":"56"},{"item":0},{"item":0},{"host":"57","user-agent":"58","content-length":"59","accept":"60","accept-encoding":"61","content-type":"62","x-forwarded-for":"63","x-forwarded-host":"57","x-forwarded-port":"64","x-forwarded-proto":"65","x-forwarded-server":"66","x-real-ip":"63"},{},{},{"user_id":"67","ram":"68","cpu":"69"},"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","production","admin.n8n.inmetech.cloud","axios/1.13.5","39","application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","gzip, compress, deflate, br","application/json","172.18.0.1","443","https","f431cf187979","1234","1g","1"]','bfa0341d-c9ac-4770-8935-19b9c2979780');
CREATE TABLE IF NOT EXISTS "shared_credentials" ("credentialsId" varchar(36) NOT NULL, "projectId" varchar(36) NOT NULL, "role" text NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_416f66fc846c7c442970c094ccf" FOREIGN KEY ("credentialsId") REFERENCES "credentials_entity" ("id") ON DELETE CASCADE, CONSTRAINT "FK_812c2852270da1247756e77f5a4" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE, PRIMARY KEY ("credentialsId", "projectId"));
CREATE TABLE IF NOT EXISTS "shared_workflow" ("workflowId" varchar(36) NOT NULL, "projectId" varchar(36) NOT NULL, "role" text NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_daa206a04983d47d0a9c34649ce" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE, CONSTRAINT "FK_a45ea5f27bcfdc21af9b4188560" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE, PRIMARY KEY ("workflowId", "projectId"));
INSERT INTO shared_workflow VALUES('ioR8eFBEVaKOkjc0','cZz5fzaW49pCUs3C','workflow:owner','2026-03-06 04:58:21.684','2026-03-06 04:58:21.684');
CREATE TABLE IF NOT EXISTS "execution_metadata" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "executionId" integer NOT NULL, "key" varchar(255) NOT NULL, "value" text NOT NULL, CONSTRAINT "FK_31d0b4c93fb85ced26f6005cda3" FOREIGN KEY ("executionId") REFERENCES "execution_entity" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "invalid_auth_token" ("token" varchar(512) PRIMARY KEY NOT NULL, "expiresAt" datetime(3) NOT NULL);
CREATE TABLE IF NOT EXISTS "execution_annotations" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "executionId" integer NOT NULL, "vote" varchar(6), "note" text, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_97f863fa83c4786f19565084960" FOREIGN KEY ("executionId") REFERENCES "execution_entity" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "annotation_tag_entity" ("id" varchar(16) PRIMARY KEY NOT NULL, "name" varchar(24) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')));
CREATE TABLE IF NOT EXISTS "execution_annotation_tags" ("annotationId" integer NOT NULL, "tagId" varchar(24) NOT NULL, CONSTRAINT "FK_c1519757391996eb06064f0e7c8" FOREIGN KEY ("annotationId") REFERENCES "execution_annotations" ("id") ON DELETE CASCADE, CONSTRAINT "FK_a3697779b366e131b2bbdae2976" FOREIGN KEY ("tagId") REFERENCES "annotation_tag_entity" ("id") ON DELETE CASCADE, PRIMARY KEY ("annotationId", "tagId"));
CREATE TABLE IF NOT EXISTS "execution_entity" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "workflowId" varchar(36) NOT NULL, "finished" boolean NOT NULL, "mode" varchar NOT NULL, "retryOf" varchar, "retrySuccessId" varchar, "startedAt" datetime, "stoppedAt" datetime, "waitTill" datetime, "status" varchar NOT NULL, "deletedAt" datetime(3), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "storedAt" VARCHAR(2) NOT NULL DEFAULT 'db' CHECK("storedAt" IN ('db', 'fs', 's3')), CONSTRAINT "FK_c4d999a5e90784e8caccf5589de" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION);
INSERT INTO execution_entity VALUES(1,'ioR8eFBEVaKOkjc0',1,'manual',NULL,NULL,'2026-03-06 05:00:11.431','2026-03-06 05:00:11.942',NULL,'success',NULL,'2026-03-06 05:00:11.403','db');
INSERT INTO execution_entity VALUES(2,'ioR8eFBEVaKOkjc0',0,'webhook',NULL,NULL,'2026-03-06 05:00:11.875','2026-03-06 05:00:11.973',NULL,'error',NULL,'2026-03-06 05:00:11.861','db');
INSERT INTO execution_entity VALUES(3,'ioR8eFBEVaKOkjc0',0,'manual',NULL,NULL,'2026-03-06 05:01:35.468','2026-03-06 05:01:35.496',NULL,'error',NULL,'2026-03-06 05:01:35.462','db');
INSERT INTO execution_entity VALUES(4,'ioR8eFBEVaKOkjc0',1,'manual',NULL,NULL,'2026-03-06 05:07:04.082','2026-03-06 05:07:04.381',NULL,'success',NULL,'2026-03-06 05:07:04.064','db');
INSERT INTO execution_entity VALUES(5,'ioR8eFBEVaKOkjc0',0,'webhook',NULL,NULL,'2026-03-06 05:07:04.308','2026-03-06 05:07:04.353',NULL,'error',NULL,'2026-03-06 05:07:04.287','db');
CREATE TABLE IF NOT EXISTS "processed_data" ("workflowId" varchar(36) NOT NULL, "context" varchar(255) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "value" text NOT NULL, CONSTRAINT "FK_06a69a7032c97a763c2c7599464" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("workflowId", "context"));
CREATE TABLE IF NOT EXISTS "folder" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(128) NOT NULL, "parentFolderId" varchar(36), "projectId" varchar(36) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_a8260b0b36939c6247f385b8221" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE, CONSTRAINT "FK_804ea52f6729e3940498bd54d78" FOREIGN KEY ("parentFolderId") REFERENCES "folder" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "folder_tag" ("folderId" varchar(36) NOT NULL, "tagId" varchar(36) NOT NULL, CONSTRAINT "FK_94a60854e06f2897b2e0d39edba" FOREIGN KEY ("folderId") REFERENCES "folder" ("id") ON DELETE CASCADE, CONSTRAINT "FK_dc88164176283de80af47621746" FOREIGN KEY ("tagId") REFERENCES "tag_entity" ("id") ON DELETE CASCADE, PRIMARY KEY ("folderId", "tagId"));
CREATE TABLE IF NOT EXISTS "insights_metadata" ("metaId" integer PRIMARY KEY NOT NULL, "workflowId" varchar(16), "projectId" varchar(36), "workflowName" varchar(128) NOT NULL, "projectName" varchar(255) NOT NULL, CONSTRAINT "FK_1d8ab99d5861c9388d2dc1cf733" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE SET NULL, CONSTRAINT "FK_2375a1eda085adb16b24615b69c" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE SET NULL);
INSERT INTO insights_metadata VALUES(1,'ioR8eFBEVaKOkjc0','cZz5fzaW49pCUs3C','Create n8n Instance','RIZOWAN rizowansiddique@gmail.com <rizowansiddique@gmail.com>');
CREATE TABLE IF NOT EXISTS "test_run" ("id" varchar(36) PRIMARY KEY NOT NULL, "workflowId" varchar(36) NOT NULL, "status" varchar NOT NULL, "errorCode" varchar, "errorDetails" text, "runAt" datetime(3), "completedAt" datetime(3), "metrics" text, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "runningInstanceId" VARCHAR(255), "cancelRequested" BOOLEAN NOT NULL DEFAULT FALSE, CONSTRAINT "FK_d6870d3b6e4c185d33926f423c8" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "scope" ("slug" varchar(128) PRIMARY KEY NOT NULL, "displayName" text, "description" text);
INSERT INTO scope VALUES('workflow:publish','Publish Workflow','Allows publishing workflows.');
INSERT INTO scope VALUES('workflow:unpublish','Unpublish Workflow','Allows unpublishing workflows.');
INSERT INTO scope VALUES('aiAssistant:manage','Manage AI Usage','Allows managing AI Usage settings.');
INSERT INTO scope VALUES('aiAssistant:*','aiAssistant:*',NULL);
INSERT INTO scope VALUES('annotationTag:create','Create Annotation Tag','Allows creating new annotation tags.');
INSERT INTO scope VALUES('annotationTag:read','annotationTag:read',NULL);
INSERT INTO scope VALUES('annotationTag:update','annotationTag:update',NULL);
INSERT INTO scope VALUES('annotationTag:delete','annotationTag:delete',NULL);
INSERT INTO scope VALUES('annotationTag:list','annotationTag:list',NULL);
INSERT INTO scope VALUES('annotationTag:*','annotationTag:*',NULL);
INSERT INTO scope VALUES('auditLogs:manage','auditLogs:manage',NULL);
INSERT INTO scope VALUES('auditLogs:*','auditLogs:*',NULL);
INSERT INTO scope VALUES('banner:dismiss','banner:dismiss',NULL);
INSERT INTO scope VALUES('banner:*','banner:*',NULL);
INSERT INTO scope VALUES('community:register','community:register',NULL);
INSERT INTO scope VALUES('community:*','community:*',NULL);
INSERT INTO scope VALUES('communityPackage:install','communityPackage:install',NULL);
INSERT INTO scope VALUES('communityPackage:uninstall','communityPackage:uninstall',NULL);
INSERT INTO scope VALUES('communityPackage:update','communityPackage:update',NULL);
INSERT INTO scope VALUES('communityPackage:list','communityPackage:list',NULL);
INSERT INTO scope VALUES('communityPackage:manage','communityPackage:manage',NULL);
INSERT INTO scope VALUES('communityPackage:*','communityPackage:*',NULL);
INSERT INTO scope VALUES('credential:share','credential:share',NULL);
INSERT INTO scope VALUES('credential:shareGlobally','credential:shareGlobally',NULL);
INSERT INTO scope VALUES('credential:move','credential:move',NULL);
INSERT INTO scope VALUES('credential:create','credential:create',NULL);
INSERT INTO scope VALUES('credential:read','credential:read',NULL);
INSERT INTO scope VALUES('credential:update','credential:update',NULL);
INSERT INTO scope VALUES('credential:delete','credential:delete',NULL);
INSERT INTO scope VALUES('credential:list','credential:list',NULL);
INSERT INTO scope VALUES('credential:*','credential:*',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:sync','externalSecretsProvider:sync',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:create','externalSecretsProvider:create',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:read','externalSecretsProvider:read',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:update','externalSecretsProvider:update',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:delete','externalSecretsProvider:delete',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:list','externalSecretsProvider:list',NULL);
INSERT INTO scope VALUES('externalSecretsProvider:*','externalSecretsProvider:*',NULL);
INSERT INTO scope VALUES('externalSecret:list','externalSecret:list',NULL);
INSERT INTO scope VALUES('externalSecret:*','externalSecret:*',NULL);
INSERT INTO scope VALUES('eventBusDestination:test','eventBusDestination:test',NULL);
INSERT INTO scope VALUES('eventBusDestination:create','eventBusDestination:create',NULL);
INSERT INTO scope VALUES('eventBusDestination:read','eventBusDestination:read',NULL);
INSERT INTO scope VALUES('eventBusDestination:update','eventBusDestination:update',NULL);
INSERT INTO scope VALUES('eventBusDestination:delete','eventBusDestination:delete',NULL);
INSERT INTO scope VALUES('eventBusDestination:list','eventBusDestination:list',NULL);
INSERT INTO scope VALUES('eventBusDestination:*','eventBusDestination:*',NULL);
INSERT INTO scope VALUES('ldap:sync','ldap:sync',NULL);
INSERT INTO scope VALUES('ldap:manage','ldap:manage',NULL);
INSERT INTO scope VALUES('ldap:*','ldap:*',NULL);
INSERT INTO scope VALUES('license:manage','license:manage',NULL);
INSERT INTO scope VALUES('license:*','license:*',NULL);
INSERT INTO scope VALUES('logStreaming:manage','logStreaming:manage',NULL);
INSERT INTO scope VALUES('logStreaming:*','logStreaming:*',NULL);
INSERT INTO scope VALUES('orchestration:read','orchestration:read',NULL);
INSERT INTO scope VALUES('orchestration:list','orchestration:list',NULL);
INSERT INTO scope VALUES('orchestration:*','orchestration:*',NULL);
INSERT INTO scope VALUES('project:create','project:create',NULL);
INSERT INTO scope VALUES('project:read','project:read',NULL);
INSERT INTO scope VALUES('project:update','project:update',NULL);
INSERT INTO scope VALUES('project:delete','project:delete',NULL);
INSERT INTO scope VALUES('project:list','project:list',NULL);
INSERT INTO scope VALUES('project:*','project:*',NULL);
INSERT INTO scope VALUES('saml:manage','saml:manage',NULL);
INSERT INTO scope VALUES('saml:*','saml:*',NULL);
INSERT INTO scope VALUES('securityAudit:generate','securityAudit:generate',NULL);
INSERT INTO scope VALUES('securityAudit:*','securityAudit:*',NULL);
INSERT INTO scope VALUES('securitySettings:manage','securitySettings:manage',NULL);
INSERT INTO scope VALUES('securitySettings:*','securitySettings:*',NULL);
INSERT INTO scope VALUES('sourceControl:pull','sourceControl:pull',NULL);
INSERT INTO scope VALUES('sourceControl:push','sourceControl:push',NULL);
INSERT INTO scope VALUES('sourceControl:manage','sourceControl:manage',NULL);
INSERT INTO scope VALUES('sourceControl:*','sourceControl:*',NULL);
INSERT INTO scope VALUES('tag:create','tag:create',NULL);
INSERT INTO scope VALUES('tag:read','tag:read',NULL);
INSERT INTO scope VALUES('tag:update','tag:update',NULL);
INSERT INTO scope VALUES('tag:delete','tag:delete',NULL);
INSERT INTO scope VALUES('tag:list','tag:list',NULL);
INSERT INTO scope VALUES('tag:*','tag:*',NULL);
INSERT INTO scope VALUES('user:resetPassword','user:resetPassword',NULL);
INSERT INTO scope VALUES('user:changeRole','user:changeRole',NULL);
INSERT INTO scope VALUES('user:enforceMfa','user:enforceMfa',NULL);
INSERT INTO scope VALUES('user:generateInviteLink','user:generateInviteLink',NULL);
INSERT INTO scope VALUES('user:create','user:create',NULL);
INSERT INTO scope VALUES('user:read','user:read',NULL);
INSERT INTO scope VALUES('user:update','user:update',NULL);
INSERT INTO scope VALUES('user:delete','user:delete',NULL);
INSERT INTO scope VALUES('user:list','user:list',NULL);
INSERT INTO scope VALUES('user:*','user:*',NULL);
INSERT INTO scope VALUES('variable:create','variable:create',NULL);
INSERT INTO scope VALUES('variable:read','variable:read',NULL);
INSERT INTO scope VALUES('variable:update','variable:update',NULL);
INSERT INTO scope VALUES('variable:delete','variable:delete',NULL);
INSERT INTO scope VALUES('variable:list','variable:list',NULL);
INSERT INTO scope VALUES('variable:*','variable:*',NULL);
INSERT INTO scope VALUES('projectVariable:create','projectVariable:create',NULL);
INSERT INTO scope VALUES('projectVariable:read','projectVariable:read',NULL);
INSERT INTO scope VALUES('projectVariable:update','projectVariable:update',NULL);
INSERT INTO scope VALUES('projectVariable:delete','projectVariable:delete',NULL);
INSERT INTO scope VALUES('projectVariable:list','projectVariable:list',NULL);
INSERT INTO scope VALUES('projectVariable:*','projectVariable:*',NULL);
INSERT INTO scope VALUES('workersView:manage','workersView:manage',NULL);
INSERT INTO scope VALUES('workersView:*','workersView:*',NULL);
INSERT INTO scope VALUES('workflow:share','workflow:share',NULL);
INSERT INTO scope VALUES('workflow:execute','workflow:execute',NULL);
INSERT INTO scope VALUES('workflow:execute-chat','workflow:execute-chat',NULL);
INSERT INTO scope VALUES('workflow:move','workflow:move',NULL);
INSERT INTO scope VALUES('workflow:activate','workflow:activate',NULL);
INSERT INTO scope VALUES('workflow:deactivate','workflow:deactivate',NULL);
INSERT INTO scope VALUES('workflow:create','workflow:create',NULL);
INSERT INTO scope VALUES('workflow:read','workflow:read',NULL);
INSERT INTO scope VALUES('workflow:update','workflow:update',NULL);
INSERT INTO scope VALUES('workflow:delete','workflow:delete',NULL);
INSERT INTO scope VALUES('workflow:list','workflow:list',NULL);
INSERT INTO scope VALUES('workflow:*','workflow:*',NULL);
INSERT INTO scope VALUES('folder:create','folder:create',NULL);
INSERT INTO scope VALUES('folder:read','folder:read',NULL);
INSERT INTO scope VALUES('folder:update','folder:update',NULL);
INSERT INTO scope VALUES('folder:delete','folder:delete',NULL);
INSERT INTO scope VALUES('folder:list','folder:list',NULL);
INSERT INTO scope VALUES('folder:move','folder:move',NULL);
INSERT INTO scope VALUES('folder:*','folder:*',NULL);
INSERT INTO scope VALUES('insights:list','insights:list',NULL);
INSERT INTO scope VALUES('insights:*','insights:*',NULL);
INSERT INTO scope VALUES('oidc:manage','oidc:manage',NULL);
INSERT INTO scope VALUES('oidc:*','oidc:*',NULL);
INSERT INTO scope VALUES('provisioning:manage','provisioning:manage',NULL);
INSERT INTO scope VALUES('provisioning:*','provisioning:*',NULL);
INSERT INTO scope VALUES('dataTable:create','dataTable:create',NULL);
INSERT INTO scope VALUES('dataTable:read','dataTable:read',NULL);
INSERT INTO scope VALUES('dataTable:update','dataTable:update',NULL);
INSERT INTO scope VALUES('dataTable:delete','dataTable:delete',NULL);
INSERT INTO scope VALUES('dataTable:list','dataTable:list',NULL);
INSERT INTO scope VALUES('dataTable:readRow','dataTable:readRow',NULL);
INSERT INTO scope VALUES('dataTable:writeRow','dataTable:writeRow',NULL);
INSERT INTO scope VALUES('dataTable:listProject','dataTable:listProject',NULL);
INSERT INTO scope VALUES('dataTable:*','dataTable:*',NULL);
INSERT INTO scope VALUES('execution:delete','execution:delete',NULL);
INSERT INTO scope VALUES('execution:read','execution:read',NULL);
INSERT INTO scope VALUES('execution:retry','execution:retry',NULL);
INSERT INTO scope VALUES('execution:list','execution:list',NULL);
INSERT INTO scope VALUES('execution:get','execution:get',NULL);
INSERT INTO scope VALUES('execution:*','execution:*',NULL);
INSERT INTO scope VALUES('workflowTags:update','workflowTags:update',NULL);
INSERT INTO scope VALUES('workflowTags:list','workflowTags:list',NULL);
INSERT INTO scope VALUES('workflowTags:*','workflowTags:*',NULL);
INSERT INTO scope VALUES('role:manage','role:manage',NULL);
INSERT INTO scope VALUES('role:*','role:*',NULL);
INSERT INTO scope VALUES('mcp:manage','mcp:manage',NULL);
INSERT INTO scope VALUES('mcp:oauth','mcp:oauth',NULL);
INSERT INTO scope VALUES('mcp:*','mcp:*',NULL);
INSERT INTO scope VALUES('mcpApiKey:create','mcpApiKey:create',NULL);
INSERT INTO scope VALUES('mcpApiKey:rotate','mcpApiKey:rotate',NULL);
INSERT INTO scope VALUES('mcpApiKey:*','mcpApiKey:*',NULL);
INSERT INTO scope VALUES('chatHub:manage','chatHub:manage',NULL);
INSERT INTO scope VALUES('chatHub:message','chatHub:message',NULL);
INSERT INTO scope VALUES('chatHub:*','chatHub:*',NULL);
INSERT INTO scope VALUES('chatHubAgent:create','chatHubAgent:create',NULL);
INSERT INTO scope VALUES('chatHubAgent:read','chatHubAgent:read',NULL);
INSERT INTO scope VALUES('chatHubAgent:update','chatHubAgent:update',NULL);
INSERT INTO scope VALUES('chatHubAgent:delete','chatHubAgent:delete',NULL);
INSERT INTO scope VALUES('chatHubAgent:list','chatHubAgent:list',NULL);
INSERT INTO scope VALUES('chatHubAgent:*','chatHubAgent:*',NULL);
INSERT INTO scope VALUES('breakingChanges:list','breakingChanges:list',NULL);
INSERT INTO scope VALUES('breakingChanges:*','breakingChanges:*',NULL);
INSERT INTO scope VALUES('apiKey:manage','apiKey:manage',NULL);
INSERT INTO scope VALUES('apiKey:*','apiKey:*',NULL);
INSERT INTO scope VALUES('credentialResolver:create','credentialResolver:create',NULL);
INSERT INTO scope VALUES('credentialResolver:read','credentialResolver:read',NULL);
INSERT INTO scope VALUES('credentialResolver:update','credentialResolver:update',NULL);
INSERT INTO scope VALUES('credentialResolver:delete','credentialResolver:delete',NULL);
INSERT INTO scope VALUES('credentialResolver:list','credentialResolver:list',NULL);
INSERT INTO scope VALUES('credentialResolver:*','credentialResolver:*',NULL);
INSERT INTO scope VALUES('*','*',NULL);
INSERT INTO scope VALUES('workflow:unshare','Unshare Workflow','Allows removing workflow shares.');
INSERT INTO scope VALUES('credential:unshare','Unshare Credential','Allows removing credential shares.');
INSERT INTO scope VALUES('workflow:updateRedactionSetting','workflow:updateRedactionSetting',NULL);
INSERT INTO scope VALUES('execution:reveal','execution:reveal',NULL);
CREATE TABLE role_scope (
					"roleSlug" VARCHAR(128) NOT NULL,
					"scopeSlug" VARCHAR(128) NOT NULL,
					CONSTRAINT "PK_role_scope" PRIMARY KEY ("roleSlug", "scopeSlug"),
					CONSTRAINT "FK_role" FOREIGN KEY ("roleSlug") REFERENCES role ("slug") ON DELETE CASCADE ON UPDATE CASCADE,
					CONSTRAINT "FK_scope" FOREIGN KEY ("scopeSlug") REFERENCES "scope" ("slug") ON DELETE CASCADE ON UPDATE CASCADE
				);
INSERT INTO role_scope VALUES('global:owner','aiAssistant:manage');
INSERT INTO role_scope VALUES('global:owner','annotationTag:create');
INSERT INTO role_scope VALUES('global:owner','annotationTag:delete');
INSERT INTO role_scope VALUES('global:owner','annotationTag:list');
INSERT INTO role_scope VALUES('global:owner','annotationTag:read');
INSERT INTO role_scope VALUES('global:owner','annotationTag:update');
INSERT INTO role_scope VALUES('global:owner','apiKey:manage');
INSERT INTO role_scope VALUES('global:owner','auditLogs:manage');
INSERT INTO role_scope VALUES('global:owner','banner:dismiss');
INSERT INTO role_scope VALUES('global:owner','breakingChanges:list');
INSERT INTO role_scope VALUES('global:owner','chatHub:manage');
INSERT INTO role_scope VALUES('global:owner','chatHub:message');
INSERT INTO role_scope VALUES('global:owner','chatHubAgent:create');
INSERT INTO role_scope VALUES('global:owner','chatHubAgent:delete');
INSERT INTO role_scope VALUES('global:owner','chatHubAgent:list');
INSERT INTO role_scope VALUES('global:owner','chatHubAgent:read');
INSERT INTO role_scope VALUES('global:owner','chatHubAgent:update');
INSERT INTO role_scope VALUES('global:owner','community:register');
INSERT INTO role_scope VALUES('global:owner','communityPackage:install');
INSERT INTO role_scope VALUES('global:owner','communityPackage:list');
INSERT INTO role_scope VALUES('global:owner','communityPackage:uninstall');
INSERT INTO role_scope VALUES('global:owner','communityPackage:update');
INSERT INTO role_scope VALUES('global:owner','credential:create');
INSERT INTO role_scope VALUES('global:owner','credential:delete');
INSERT INTO role_scope VALUES('global:owner','credential:list');
INSERT INTO role_scope VALUES('global:owner','credential:move');
INSERT INTO role_scope VALUES('global:owner','credential:read');
INSERT INTO role_scope VALUES('global:owner','credential:share');
INSERT INTO role_scope VALUES('global:owner','credential:shareGlobally');
INSERT INTO role_scope VALUES('global:owner','credential:update');
INSERT INTO role_scope VALUES('global:owner','credentialResolver:create');
INSERT INTO role_scope VALUES('global:owner','credentialResolver:delete');
INSERT INTO role_scope VALUES('global:owner','credentialResolver:list');
INSERT INTO role_scope VALUES('global:owner','credentialResolver:read');
INSERT INTO role_scope VALUES('global:owner','credentialResolver:update');
INSERT INTO role_scope VALUES('global:owner','dataTable:create');
INSERT INTO role_scope VALUES('global:owner','dataTable:delete');
INSERT INTO role_scope VALUES('global:owner','dataTable:list');
INSERT INTO role_scope VALUES('global:owner','dataTable:listProject');
INSERT INTO role_scope VALUES('global:owner','dataTable:read');
INSERT INTO role_scope VALUES('global:owner','dataTable:readRow');
INSERT INTO role_scope VALUES('global:owner','dataTable:update');
INSERT INTO role_scope VALUES('global:owner','dataTable:writeRow');
INSERT INTO role_scope VALUES('global:owner','eventBusDestination:create');
INSERT INTO role_scope VALUES('global:owner','eventBusDestination:delete');
INSERT INTO role_scope VALUES('global:owner','eventBusDestination:list');
INSERT INTO role_scope VALUES('global:owner','eventBusDestination:read');
INSERT INTO role_scope VALUES('global:owner','eventBusDestination:test');
INSERT INTO role_scope VALUES('global:owner','eventBusDestination:update');
INSERT INTO role_scope VALUES('global:owner','externalSecret:list');
INSERT INTO role_scope VALUES('global:owner','externalSecretsProvider:create');
INSERT INTO role_scope VALUES('global:owner','externalSecretsProvider:delete');
INSERT INTO role_scope VALUES('global:owner','externalSecretsProvider:list');
INSERT INTO role_scope VALUES('global:owner','externalSecretsProvider:read');
INSERT INTO role_scope VALUES('global:owner','externalSecretsProvider:sync');
INSERT INTO role_scope VALUES('global:owner','externalSecretsProvider:update');
INSERT INTO role_scope VALUES('global:owner','folder:create');
INSERT INTO role_scope VALUES('global:owner','folder:delete');
INSERT INTO role_scope VALUES('global:owner','folder:list');
INSERT INTO role_scope VALUES('global:owner','folder:move');
INSERT INTO role_scope VALUES('global:owner','folder:read');
INSERT INTO role_scope VALUES('global:owner','folder:update');
INSERT INTO role_scope VALUES('global:owner','insights:list');
INSERT INTO role_scope VALUES('global:owner','ldap:manage');
INSERT INTO role_scope VALUES('global:owner','ldap:sync');
INSERT INTO role_scope VALUES('global:owner','license:manage');
INSERT INTO role_scope VALUES('global:owner','logStreaming:manage');
INSERT INTO role_scope VALUES('global:owner','mcp:manage');
INSERT INTO role_scope VALUES('global:owner','mcp:oauth');
INSERT INTO role_scope VALUES('global:owner','mcpApiKey:create');
INSERT INTO role_scope VALUES('global:owner','mcpApiKey:rotate');
INSERT INTO role_scope VALUES('global:owner','oidc:manage');
INSERT INTO role_scope VALUES('global:owner','orchestration:read');
INSERT INTO role_scope VALUES('global:owner','project:create');
INSERT INTO role_scope VALUES('global:owner','project:delete');
INSERT INTO role_scope VALUES('global:owner','project:list');
INSERT INTO role_scope VALUES('global:owner','project:read');
INSERT INTO role_scope VALUES('global:owner','project:update');
INSERT INTO role_scope VALUES('global:owner','projectVariable:create');
INSERT INTO role_scope VALUES('global:owner','projectVariable:delete');
INSERT INTO role_scope VALUES('global:owner','projectVariable:list');
INSERT INTO role_scope VALUES('global:owner','projectVariable:read');
INSERT INTO role_scope VALUES('global:owner','projectVariable:update');
INSERT INTO role_scope VALUES('global:owner','provisioning:manage');
INSERT INTO role_scope VALUES('global:owner','role:manage');
INSERT INTO role_scope VALUES('global:owner','saml:manage');
INSERT INTO role_scope VALUES('global:owner','securityAudit:generate');
INSERT INTO role_scope VALUES('global:owner','securitySettings:manage');
INSERT INTO role_scope VALUES('global:owner','sourceControl:manage');
INSERT INTO role_scope VALUES('global:owner','sourceControl:pull');
INSERT INTO role_scope VALUES('global:owner','sourceControl:push');
INSERT INTO role_scope VALUES('global:owner','tag:create');
INSERT INTO role_scope VALUES('global:owner','tag:delete');
INSERT INTO role_scope VALUES('global:owner','tag:list');
INSERT INTO role_scope VALUES('global:owner','tag:read');
INSERT INTO role_scope VALUES('global:owner','tag:update');
INSERT INTO role_scope VALUES('global:owner','user:changeRole');
INSERT INTO role_scope VALUES('global:owner','user:create');
INSERT INTO role_scope VALUES('global:owner','user:delete');
INSERT INTO role_scope VALUES('global:owner','user:enforceMfa');
INSERT INTO role_scope VALUES('global:owner','user:generateInviteLink');
INSERT INTO role_scope VALUES('global:owner','user:list');
INSERT INTO role_scope VALUES('global:owner','user:read');
INSERT INTO role_scope VALUES('global:owner','user:resetPassword');
INSERT INTO role_scope VALUES('global:owner','user:update');
INSERT INTO role_scope VALUES('global:owner','variable:create');
INSERT INTO role_scope VALUES('global:owner','variable:delete');
INSERT INTO role_scope VALUES('global:owner','variable:list');
INSERT INTO role_scope VALUES('global:owner','variable:read');
INSERT INTO role_scope VALUES('global:owner','variable:update');
INSERT INTO role_scope VALUES('global:owner','workersView:manage');
INSERT INTO role_scope VALUES('global:owner','workflow:create');
INSERT INTO role_scope VALUES('global:owner','workflow:delete');
INSERT INTO role_scope VALUES('global:owner','workflow:execute');
INSERT INTO role_scope VALUES('global:owner','workflow:execute-chat');
INSERT INTO role_scope VALUES('global:owner','workflow:list');
INSERT INTO role_scope VALUES('global:owner','workflow:move');
INSERT INTO role_scope VALUES('global:owner','workflow:publish');
INSERT INTO role_scope VALUES('global:owner','workflow:read');
INSERT INTO role_scope VALUES('global:owner','workflow:share');
INSERT INTO role_scope VALUES('global:owner','workflow:update');
INSERT INTO role_scope VALUES('global:admin','aiAssistant:manage');
INSERT INTO role_scope VALUES('global:admin','annotationTag:create');
INSERT INTO role_scope VALUES('global:admin','annotationTag:delete');
INSERT INTO role_scope VALUES('global:admin','annotationTag:list');
INSERT INTO role_scope VALUES('global:admin','annotationTag:read');
INSERT INTO role_scope VALUES('global:admin','annotationTag:update');
INSERT INTO role_scope VALUES('global:admin','apiKey:manage');
INSERT INTO role_scope VALUES('global:admin','auditLogs:manage');
INSERT INTO role_scope VALUES('global:admin','banner:dismiss');
INSERT INTO role_scope VALUES('global:admin','breakingChanges:list');
INSERT INTO role_scope VALUES('global:admin','chatHub:manage');
INSERT INTO role_scope VALUES('global:admin','chatHub:message');
INSERT INTO role_scope VALUES('global:admin','chatHubAgent:create');
INSERT INTO role_scope VALUES('global:admin','chatHubAgent:delete');
INSERT INTO role_scope VALUES('global:admin','chatHubAgent:list');
INSERT INTO role_scope VALUES('global:admin','chatHubAgent:read');
INSERT INTO role_scope VALUES('global:admin','chatHubAgent:update');
INSERT INTO role_scope VALUES('global:admin','community:register');
INSERT INTO role_scope VALUES('global:admin','communityPackage:install');
INSERT INTO role_scope VALUES('global:admin','communityPackage:list');
INSERT INTO role_scope VALUES('global:admin','communityPackage:uninstall');
INSERT INTO role_scope VALUES('global:admin','communityPackage:update');
INSERT INTO role_scope VALUES('global:admin','credential:create');
INSERT INTO role_scope VALUES('global:admin','credential:delete');
INSERT INTO role_scope VALUES('global:admin','credential:list');
INSERT INTO role_scope VALUES('global:admin','credential:move');
INSERT INTO role_scope VALUES('global:admin','credential:read');
INSERT INTO role_scope VALUES('global:admin','credential:share');
INSERT INTO role_scope VALUES('global:admin','credential:shareGlobally');
INSERT INTO role_scope VALUES('global:admin','credential:update');
INSERT INTO role_scope VALUES('global:admin','credentialResolver:create');
INSERT INTO role_scope VALUES('global:admin','credentialResolver:delete');
INSERT INTO role_scope VALUES('global:admin','credentialResolver:list');
INSERT INTO role_scope VALUES('global:admin','credentialResolver:read');
INSERT INTO role_scope VALUES('global:admin','credentialResolver:update');
INSERT INTO role_scope VALUES('global:admin','dataTable:create');
INSERT INTO role_scope VALUES('global:admin','dataTable:delete');
INSERT INTO role_scope VALUES('global:admin','dataTable:list');
INSERT INTO role_scope VALUES('global:admin','dataTable:listProject');
INSERT INTO role_scope VALUES('global:admin','dataTable:read');
INSERT INTO role_scope VALUES('global:admin','dataTable:readRow');
INSERT INTO role_scope VALUES('global:admin','dataTable:update');
INSERT INTO role_scope VALUES('global:admin','dataTable:writeRow');
INSERT INTO role_scope VALUES('global:admin','eventBusDestination:create');
INSERT INTO role_scope VALUES('global:admin','eventBusDestination:delete');
INSERT INTO role_scope VALUES('global:admin','eventBusDestination:list');
INSERT INTO role_scope VALUES('global:admin','eventBusDestination:read');
INSERT INTO role_scope VALUES('global:admin','eventBusDestination:test');
INSERT INTO role_scope VALUES('global:admin','eventBusDestination:update');
INSERT INTO role_scope VALUES('global:admin','externalSecret:list');
INSERT INTO role_scope VALUES('global:admin','externalSecretsProvider:create');
INSERT INTO role_scope VALUES('global:admin','externalSecretsProvider:delete');
INSERT INTO role_scope VALUES('global:admin','externalSecretsProvider:list');
INSERT INTO role_scope VALUES('global:admin','externalSecretsProvider:read');
INSERT INTO role_scope VALUES('global:admin','externalSecretsProvider:sync');
INSERT INTO role_scope VALUES('global:admin','externalSecretsProvider:update');
INSERT INTO role_scope VALUES('global:admin','folder:create');
INSERT INTO role_scope VALUES('global:admin','folder:delete');
INSERT INTO role_scope VALUES('global:admin','folder:list');
INSERT INTO role_scope VALUES('global:admin','folder:move');
INSERT INTO role_scope VALUES('global:admin','folder:read');
INSERT INTO role_scope VALUES('global:admin','folder:update');
INSERT INTO role_scope VALUES('global:admin','insights:list');
INSERT INTO role_scope VALUES('global:admin','ldap:manage');
INSERT INTO role_scope VALUES('global:admin','ldap:sync');
INSERT INTO role_scope VALUES('global:admin','license:manage');
INSERT INTO role_scope VALUES('global:admin','logStreaming:manage');
INSERT INTO role_scope VALUES('global:admin','mcp:manage');
INSERT INTO role_scope VALUES('global:admin','mcp:oauth');
INSERT INTO role_scope VALUES('global:admin','mcpApiKey:create');
INSERT INTO role_scope VALUES('global:admin','mcpApiKey:rotate');
INSERT INTO role_scope VALUES('global:admin','oidc:manage');
INSERT INTO role_scope VALUES('global:admin','orchestration:read');
INSERT INTO role_scope VALUES('global:admin','project:create');
INSERT INTO role_scope VALUES('global:admin','project:delete');
INSERT INTO role_scope VALUES('global:admin','project:list');
INSERT INTO role_scope VALUES('global:admin','project:read');
INSERT INTO role_scope VALUES('global:admin','project:update');
INSERT INTO role_scope VALUES('global:admin','projectVariable:create');
INSERT INTO role_scope VALUES('global:admin','projectVariable:delete');
INSERT INTO role_scope VALUES('global:admin','projectVariable:list');
INSERT INTO role_scope VALUES('global:admin','projectVariable:read');
INSERT INTO role_scope VALUES('global:admin','projectVariable:update');
INSERT INTO role_scope VALUES('global:admin','provisioning:manage');
INSERT INTO role_scope VALUES('global:admin','role:manage');
INSERT INTO role_scope VALUES('global:admin','saml:manage');
INSERT INTO role_scope VALUES('global:admin','securityAudit:generate');
INSERT INTO role_scope VALUES('global:admin','securitySettings:manage');
INSERT INTO role_scope VALUES('global:admin','sourceControl:manage');
INSERT INTO role_scope VALUES('global:admin','sourceControl:pull');
INSERT INTO role_scope VALUES('global:admin','sourceControl:push');
INSERT INTO role_scope VALUES('global:admin','tag:create');
INSERT INTO role_scope VALUES('global:admin','tag:delete');
INSERT INTO role_scope VALUES('global:admin','tag:list');
INSERT INTO role_scope VALUES('global:admin','tag:read');
INSERT INTO role_scope VALUES('global:admin','tag:update');
INSERT INTO role_scope VALUES('global:admin','user:changeRole');
INSERT INTO role_scope VALUES('global:admin','user:create');
INSERT INTO role_scope VALUES('global:admin','user:delete');
INSERT INTO role_scope VALUES('global:admin','user:enforceMfa');
INSERT INTO role_scope VALUES('global:admin','user:generateInviteLink');
INSERT INTO role_scope VALUES('global:admin','user:list');
INSERT INTO role_scope VALUES('global:admin','user:read');
INSERT INTO role_scope VALUES('global:admin','user:resetPassword');
INSERT INTO role_scope VALUES('global:admin','user:update');
INSERT INTO role_scope VALUES('global:admin','variable:create');
INSERT INTO role_scope VALUES('global:admin','variable:delete');
INSERT INTO role_scope VALUES('global:admin','variable:list');
INSERT INTO role_scope VALUES('global:admin','variable:read');
INSERT INTO role_scope VALUES('global:admin','variable:update');
INSERT INTO role_scope VALUES('global:admin','workersView:manage');
INSERT INTO role_scope VALUES('global:admin','workflow:create');
INSERT INTO role_scope VALUES('global:admin','workflow:delete');
INSERT INTO role_scope VALUES('global:admin','workflow:execute');
INSERT INTO role_scope VALUES('global:admin','workflow:execute-chat');
INSERT INTO role_scope VALUES('global:admin','workflow:list');
INSERT INTO role_scope VALUES('global:admin','workflow:move');
INSERT INTO role_scope VALUES('global:admin','workflow:publish');
INSERT INTO role_scope VALUES('global:admin','workflow:read');
INSERT INTO role_scope VALUES('global:admin','workflow:share');
INSERT INTO role_scope VALUES('global:admin','workflow:update');
INSERT INTO role_scope VALUES('global:member','annotationTag:create');
INSERT INTO role_scope VALUES('global:member','annotationTag:delete');
INSERT INTO role_scope VALUES('global:member','annotationTag:list');
INSERT INTO role_scope VALUES('global:member','annotationTag:read');
INSERT INTO role_scope VALUES('global:member','annotationTag:update');
INSERT INTO role_scope VALUES('global:member','apiKey:manage');
INSERT INTO role_scope VALUES('global:member','chatHub:message');
INSERT INTO role_scope VALUES('global:member','chatHubAgent:create');
INSERT INTO role_scope VALUES('global:member','chatHubAgent:delete');
INSERT INTO role_scope VALUES('global:member','chatHubAgent:list');
INSERT INTO role_scope VALUES('global:member','chatHubAgent:read');
INSERT INTO role_scope VALUES('global:member','chatHubAgent:update');
INSERT INTO role_scope VALUES('global:member','dataTable:list');
INSERT INTO role_scope VALUES('global:member','eventBusDestination:list');
INSERT INTO role_scope VALUES('global:member','eventBusDestination:test');
INSERT INTO role_scope VALUES('global:member','mcp:oauth');
INSERT INTO role_scope VALUES('global:member','mcpApiKey:create');
INSERT INTO role_scope VALUES('global:member','mcpApiKey:rotate');
INSERT INTO role_scope VALUES('global:member','tag:create');
INSERT INTO role_scope VALUES('global:member','tag:list');
INSERT INTO role_scope VALUES('global:member','tag:read');
INSERT INTO role_scope VALUES('global:member','tag:update');
INSERT INTO role_scope VALUES('global:member','user:list');
INSERT INTO role_scope VALUES('global:member','variable:list');
INSERT INTO role_scope VALUES('global:member','variable:read');
INSERT INTO role_scope VALUES('global:chatUser','chatHub:message');
INSERT INTO role_scope VALUES('global:chatUser','chatHubAgent:create');
INSERT INTO role_scope VALUES('global:chatUser','chatHubAgent:delete');
INSERT INTO role_scope VALUES('global:chatUser','chatHubAgent:list');
INSERT INTO role_scope VALUES('global:chatUser','chatHubAgent:read');
INSERT INTO role_scope VALUES('global:chatUser','chatHubAgent:update');
INSERT INTO role_scope VALUES('project:admin','credential:create');
INSERT INTO role_scope VALUES('project:admin','credential:delete');
INSERT INTO role_scope VALUES('project:admin','credential:list');
INSERT INTO role_scope VALUES('project:admin','credential:move');
INSERT INTO role_scope VALUES('project:admin','credential:read');
INSERT INTO role_scope VALUES('project:admin','credential:share');
INSERT INTO role_scope VALUES('project:admin','credential:update');
INSERT INTO role_scope VALUES('project:admin','dataTable:create');
INSERT INTO role_scope VALUES('project:admin','dataTable:delete');
INSERT INTO role_scope VALUES('project:admin','dataTable:listProject');
INSERT INTO role_scope VALUES('project:admin','dataTable:read');
INSERT INTO role_scope VALUES('project:admin','dataTable:readRow');
INSERT INTO role_scope VALUES('project:admin','dataTable:update');
INSERT INTO role_scope VALUES('project:admin','dataTable:writeRow');
INSERT INTO role_scope VALUES('project:admin','folder:create');
INSERT INTO role_scope VALUES('project:admin','folder:delete');
INSERT INTO role_scope VALUES('project:admin','folder:list');
INSERT INTO role_scope VALUES('project:admin','folder:move');
INSERT INTO role_scope VALUES('project:admin','folder:read');
INSERT INTO role_scope VALUES('project:admin','folder:update');
INSERT INTO role_scope VALUES('project:admin','project:delete');
INSERT INTO role_scope VALUES('project:admin','project:list');
INSERT INTO role_scope VALUES('project:admin','project:read');
INSERT INTO role_scope VALUES('project:admin','project:update');
INSERT INTO role_scope VALUES('project:admin','projectVariable:create');
INSERT INTO role_scope VALUES('project:admin','projectVariable:delete');
INSERT INTO role_scope VALUES('project:admin','projectVariable:list');
INSERT INTO role_scope VALUES('project:admin','projectVariable:read');
INSERT INTO role_scope VALUES('project:admin','projectVariable:update');
INSERT INTO role_scope VALUES('project:admin','sourceControl:push');
INSERT INTO role_scope VALUES('project:admin','workflow:create');
INSERT INTO role_scope VALUES('project:admin','workflow:delete');
INSERT INTO role_scope VALUES('project:admin','workflow:execute');
INSERT INTO role_scope VALUES('project:admin','workflow:execute-chat');
INSERT INTO role_scope VALUES('project:admin','workflow:list');
INSERT INTO role_scope VALUES('project:admin','workflow:move');
INSERT INTO role_scope VALUES('project:admin','workflow:publish');
INSERT INTO role_scope VALUES('project:admin','workflow:read');
INSERT INTO role_scope VALUES('project:admin','workflow:unpublish');
INSERT INTO role_scope VALUES('project:admin','workflow:update');
INSERT INTO role_scope VALUES('project:personalOwner','credential:create');
INSERT INTO role_scope VALUES('project:personalOwner','credential:delete');
INSERT INTO role_scope VALUES('project:personalOwner','credential:list');
INSERT INTO role_scope VALUES('project:personalOwner','credential:move');
INSERT INTO role_scope VALUES('project:personalOwner','credential:read');
INSERT INTO role_scope VALUES('project:personalOwner','credential:share');
INSERT INTO role_scope VALUES('project:personalOwner','credential:update');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:create');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:delete');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:listProject');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:read');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:readRow');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:update');
INSERT INTO role_scope VALUES('project:personalOwner','dataTable:writeRow');
INSERT INTO role_scope VALUES('project:personalOwner','folder:create');
INSERT INTO role_scope VALUES('project:personalOwner','folder:delete');
INSERT INTO role_scope VALUES('project:personalOwner','folder:list');
INSERT INTO role_scope VALUES('project:personalOwner','folder:move');
INSERT INTO role_scope VALUES('project:personalOwner','folder:read');
INSERT INTO role_scope VALUES('project:personalOwner','folder:update');
INSERT INTO role_scope VALUES('project:personalOwner','project:list');
INSERT INTO role_scope VALUES('project:personalOwner','project:read');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:create');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:delete');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:execute');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:execute-chat');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:list');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:move');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:publish');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:read');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:share');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:unpublish');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:update');
INSERT INTO role_scope VALUES('project:editor','credential:create');
INSERT INTO role_scope VALUES('project:editor','credential:delete');
INSERT INTO role_scope VALUES('project:editor','credential:list');
INSERT INTO role_scope VALUES('project:editor','credential:read');
INSERT INTO role_scope VALUES('project:editor','credential:update');
INSERT INTO role_scope VALUES('project:editor','dataTable:create');
INSERT INTO role_scope VALUES('project:editor','dataTable:delete');
INSERT INTO role_scope VALUES('project:editor','dataTable:listProject');
INSERT INTO role_scope VALUES('project:editor','dataTable:read');
INSERT INTO role_scope VALUES('project:editor','dataTable:readRow');
INSERT INTO role_scope VALUES('project:editor','dataTable:update');
INSERT INTO role_scope VALUES('project:editor','dataTable:writeRow');
INSERT INTO role_scope VALUES('project:editor','folder:create');
INSERT INTO role_scope VALUES('project:editor','folder:delete');
INSERT INTO role_scope VALUES('project:editor','folder:list');
INSERT INTO role_scope VALUES('project:editor','folder:read');
INSERT INTO role_scope VALUES('project:editor','folder:update');
INSERT INTO role_scope VALUES('project:editor','project:list');
INSERT INTO role_scope VALUES('project:editor','project:read');
INSERT INTO role_scope VALUES('project:editor','projectVariable:create');
INSERT INTO role_scope VALUES('project:editor','projectVariable:delete');
INSERT INTO role_scope VALUES('project:editor','projectVariable:list');
INSERT INTO role_scope VALUES('project:editor','projectVariable:read');
INSERT INTO role_scope VALUES('project:editor','projectVariable:update');
INSERT INTO role_scope VALUES('project:editor','workflow:create');
INSERT INTO role_scope VALUES('project:editor','workflow:delete');
INSERT INTO role_scope VALUES('project:editor','workflow:execute');
INSERT INTO role_scope VALUES('project:editor','workflow:execute-chat');
INSERT INTO role_scope VALUES('project:editor','workflow:list');
INSERT INTO role_scope VALUES('project:editor','workflow:publish');
INSERT INTO role_scope VALUES('project:editor','workflow:read');
INSERT INTO role_scope VALUES('project:editor','workflow:unpublish');
INSERT INTO role_scope VALUES('project:editor','workflow:update');
INSERT INTO role_scope VALUES('project:viewer','credential:list');
INSERT INTO role_scope VALUES('project:viewer','credential:read');
INSERT INTO role_scope VALUES('project:viewer','dataTable:listProject');
INSERT INTO role_scope VALUES('project:viewer','dataTable:read');
INSERT INTO role_scope VALUES('project:viewer','dataTable:readRow');
INSERT INTO role_scope VALUES('project:viewer','folder:list');
INSERT INTO role_scope VALUES('project:viewer','folder:read');
INSERT INTO role_scope VALUES('project:viewer','project:list');
INSERT INTO role_scope VALUES('project:viewer','project:read');
INSERT INTO role_scope VALUES('project:viewer','projectVariable:list');
INSERT INTO role_scope VALUES('project:viewer','projectVariable:read');
INSERT INTO role_scope VALUES('project:viewer','workflow:execute-chat');
INSERT INTO role_scope VALUES('project:viewer','workflow:list');
INSERT INTO role_scope VALUES('project:viewer','workflow:read');
INSERT INTO role_scope VALUES('project:chatUser','workflow:execute-chat');
INSERT INTO role_scope VALUES('credential:owner','credential:delete');
INSERT INTO role_scope VALUES('credential:owner','credential:move');
INSERT INTO role_scope VALUES('credential:owner','credential:read');
INSERT INTO role_scope VALUES('credential:owner','credential:share');
INSERT INTO role_scope VALUES('credential:owner','credential:update');
INSERT INTO role_scope VALUES('credential:user','credential:read');
INSERT INTO role_scope VALUES('workflow:owner','workflow:delete');
INSERT INTO role_scope VALUES('workflow:owner','workflow:execute');
INSERT INTO role_scope VALUES('workflow:owner','workflow:execute-chat');
INSERT INTO role_scope VALUES('workflow:owner','workflow:move');
INSERT INTO role_scope VALUES('workflow:owner','workflow:publish');
INSERT INTO role_scope VALUES('workflow:owner','workflow:read');
INSERT INTO role_scope VALUES('workflow:owner','workflow:share');
INSERT INTO role_scope VALUES('workflow:owner','workflow:unpublish');
INSERT INTO role_scope VALUES('workflow:owner','workflow:update');
INSERT INTO role_scope VALUES('workflow:editor','workflow:execute');
INSERT INTO role_scope VALUES('workflow:editor','workflow:execute-chat');
INSERT INTO role_scope VALUES('workflow:editor','workflow:publish');
INSERT INTO role_scope VALUES('workflow:editor','workflow:read');
INSERT INTO role_scope VALUES('workflow:editor','workflow:unpublish');
INSERT INTO role_scope VALUES('workflow:editor','workflow:update');
INSERT INTO role_scope VALUES('global:owner','workflow:unshare');
INSERT INTO role_scope VALUES('global:admin','workflow:unshare');
INSERT INTO role_scope VALUES('workflow:owner','workflow:unshare');
INSERT INTO role_scope VALUES('global:owner','credential:unshare');
INSERT INTO role_scope VALUES('global:admin','credential:unshare');
INSERT INTO role_scope VALUES('project:admin','credential:unshare');
INSERT INTO role_scope VALUES('credential:owner','credential:unshare');
INSERT INTO role_scope VALUES('global:owner','execution:reveal');
INSERT INTO role_scope VALUES('global:owner','workflow:unpublish');
INSERT INTO role_scope VALUES('global:owner','workflow:updateRedactionSetting');
INSERT INTO role_scope VALUES('global:admin','execution:reveal');
INSERT INTO role_scope VALUES('global:admin','workflow:unpublish');
INSERT INTO role_scope VALUES('global:admin','workflow:updateRedactionSetting');
INSERT INTO role_scope VALUES('global:member','credentialResolver:list');
INSERT INTO role_scope VALUES('project:admin','execution:reveal');
INSERT INTO role_scope VALUES('project:admin','workflow:updateRedactionSetting');
INSERT INTO role_scope VALUES('project:personalOwner','credential:unshare');
INSERT INTO role_scope VALUES('project:personalOwner','execution:reveal');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:unshare');
INSERT INTO role_scope VALUES('project:personalOwner','workflow:updateRedactionSetting');
INSERT INTO role_scope VALUES('secretsProviderConnection:owner','externalSecret:list');
INSERT INTO role_scope VALUES('secretsProviderConnection:owner','externalSecretsProvider:delete');
INSERT INTO role_scope VALUES('secretsProviderConnection:owner','externalSecretsProvider:list');
INSERT INTO role_scope VALUES('secretsProviderConnection:owner','externalSecretsProvider:read');
INSERT INTO role_scope VALUES('secretsProviderConnection:owner','externalSecretsProvider:sync');
INSERT INTO role_scope VALUES('secretsProviderConnection:owner','externalSecretsProvider:update');
INSERT INTO role_scope VALUES('secretsProviderConnection:user','externalSecret:list');
INSERT INTO role_scope VALUES('secretsProviderConnection:user','externalSecretsProvider:list');
INSERT INTO role_scope VALUES('secretsProviderConnection:user','externalSecretsProvider:read');
CREATE TABLE IF NOT EXISTS "user" ("id" varchar PRIMARY KEY, "email" varchar(255), "firstName" varchar(32), "lastName" varchar(32), "password" varchar, "personalizationAnswers" text, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "settings" text, "disabled" boolean NOT NULL DEFAULT (FALSE), "mfaEnabled" boolean NOT NULL DEFAULT (FALSE), "mfaSecret" text, "mfaRecoveryCodes" text, "lastActiveAt" date, "roleSlug" varchar(128) NOT NULL DEFAULT ('global:member'), CONSTRAINT "UQ_e12875dfb3b1d92d7d7c5377e22" UNIQUE ("email"), CONSTRAINT "FK_eaea92ee7bfb9c1b6cd01505d56" FOREIGN KEY ("roleSlug") REFERENCES "role" ("slug"));
INSERT INTO user VALUES('3f77e136-dc7a-4d58-8dc6-817cb2b88866','rizowansiddique@gmail.com','RIZOWAN','rizowansiddique@gmail.com','$2a$10$a5BxANs3UkqwfXY5dKFbse289gvU7SjgGdFLh48DD86ylcOhi0iwC','{"version":"v4","personalization_survey_submitted_at":"2026-03-06T04:58:07.143Z","personalization_survey_n8n_version":"2.10.3"}','2026-03-06 04:57:50.744','2026-03-06 04:58:06','{"userActivated":false}',0,0,NULL,NULL,'2026-03-06','global:owner');
CREATE TABLE IF NOT EXISTS "test_case_execution" ("id" varchar(36) PRIMARY KEY NOT NULL, "testRunId" varchar(36) NOT NULL, "pastExecutionId" integer, "executionId" integer, "evaluationExecutionId" integer, "status" varchar NOT NULL, "runAt" datetime(3), "completedAt" datetime(3), "errorCode" varchar, "errorDetails" text, "metrics" text, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "inputs" text, "outputs" text, CONSTRAINT "FK_dfbe194e3ebdfe49a87bc4692ca" FOREIGN KEY ("evaluationExecutionId") REFERENCES "execution_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_e48965fac35d0f5b9e7f51d8c44" FOREIGN KEY ("executionId") REFERENCES "execution_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_258d954733841d51edd826a562b" FOREIGN KEY ("pastExecutionId") REFERENCES "execution_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_8e4b4774db42f1e6dda3452b2af" FOREIGN KEY ("testRunId") REFERENCES "test_run" ("id") ON DELETE CASCADE ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS "project_relation" ("projectId" varchar(36) NOT NULL, "userId" varchar NOT NULL, "role" varchar NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_5f0643f6717905a05164090dde7" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_61448d56d61802b5dfde5cdb002" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_c6b99592dc96b0d836d7a21db91" FOREIGN KEY ("role") REFERENCES "role" ("slug"), PRIMARY KEY ("projectId", "userId"));
INSERT INTO project_relation VALUES('cZz5fzaW49pCUs3C','3f77e136-dc7a-4d58-8dc6-817cb2b88866','project:personalOwner','2026-03-06 04:57:51.085','2026-03-06 04:57:51.085');
CREATE TABLE IF NOT EXISTS "data_table" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(128) NOT NULL, "projectId" varchar(36) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "UQ_b23096ef747281ac944d28e8b0d" UNIQUE ("projectId", "name"), CONSTRAINT "FK_c2a794257dee48af7c9abf681de" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "data_table_column" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(128) NOT NULL, "type" varchar(32) NOT NULL, "index" integer NOT NULL, "dataTableId" varchar(36) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "UQ_8082ec4890f892f0bc77473a123" UNIQUE ("dataTableId", "name"), CONSTRAINT "FK_930b6e8faaf88294cef23484160" FOREIGN KEY ("dataTableId") REFERENCES "data_table" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "role" ("slug" varchar(128) PRIMARY KEY NOT NULL, "displayName" text, "description" text, "roleType" text, "systemRole" boolean NOT NULL DEFAULT (false), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')));
INSERT INTO role VALUES('global:owner','Owner','Owner','global',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.968');
INSERT INTO role VALUES('global:admin','Admin','Admin','global',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.968');
INSERT INTO role VALUES('global:member','Member','Member','global',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.968');
INSERT INTO role VALUES('project:personalOwner','Project Owner','Project Owner','project',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.985');
INSERT INTO role VALUES('project:admin','Project Admin','Full control of settings, members, workflows, credentials and executions','project',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.985');
INSERT INTO role VALUES('project:editor','Project Editor','Create, edit, and delete workflows, credentials, and executions','project',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.985');
INSERT INTO role VALUES('project:viewer','Project Viewer','Read-only access to workflows, credentials, and executions','project',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.985');
INSERT INTO role VALUES('project:chatUser','Project Chat User','Chat-only access to chatting with workflows that have n8n Chat enabled','project',1,'2026-03-06 04:57:51.399','2026-03-06 04:57:51.985');
INSERT INTO role VALUES('global:chatUser','Chat User','Chat User','global',1,'2026-03-06 04:57:51.971','2026-03-06 04:57:51.971');
INSERT INTO role VALUES('credential:owner','Credential Owner','Credential Owner','credential',1,'2026-03-06 04:57:51.994','2026-03-06 04:57:51.994');
INSERT INTO role VALUES('credential:user','Credential User','Credential User','credential',1,'2026-03-06 04:57:51.994','2026-03-06 04:57:51.994');
INSERT INTO role VALUES('workflow:owner','Workflow Owner','Workflow Owner','workflow',1,'2026-03-06 04:57:51.998','2026-03-06 04:57:51.998');
INSERT INTO role VALUES('workflow:editor','Workflow Editor','Workflow Editor','workflow',1,'2026-03-06 04:57:51.999','2026-03-06 04:57:51.999');
INSERT INTO role VALUES('secretsProviderConnection:owner','Secrets Provider Connection Owner','Full control of secrets provider connection settings and secrets','secretsProviderConnection',1,'2026-03-25 18:55:27.859','2026-03-25 18:55:27.859');
INSERT INTO role VALUES('secretsProviderConnection:user','Secrets Provider Connection User','Read-only access to use secrets from the connection','secretsProviderConnection',1,'2026-03-25 18:55:27.861','2026-03-25 18:55:27.861');
CREATE TABLE IF NOT EXISTS "user_api_keys" ("id" varchar(36) PRIMARY KEY NOT NULL, "userId" varchar NOT NULL, "label" varchar(100) NOT NULL, "apiKey" varchar NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "scopes" text, "audience" varchar NOT NULL DEFAULT ('public-api'), CONSTRAINT "UQ_63d7bbae72c767cf162d459fccd" UNIQUE ("userId", "label"), CONSTRAINT "UQ_1ef35bac35d20bdae979d917a36" UNIQUE ("apiKey"), CONSTRAINT "FK_e131705cbbc8fb589889b02d457" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS "variables" ("id" varchar(36) PRIMARY KEY NOT NULL, "key" text NOT NULL, "type" text NOT NULL DEFAULT ('string'), "value" text, "projectId" varchar(36), CONSTRAINT "FK_a0f13eaa709a21b77a3a9721319" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "insights_raw" ("id" integer PRIMARY KEY NOT NULL, "metaId" integer NOT NULL, "type" integer NOT NULL, "value" bigint NOT NULL, "timestamp" datetime(0) NOT NULL DEFAULT (CURRENT_TIMESTAMP), CONSTRAINT "FK_d66d942bc9907488832eb0eed81" FOREIGN KEY ("metaId") REFERENCES "insights_metadata" ("metaId") ON DELETE CASCADE);
INSERT INTO insights_raw VALUES(1,1,3,1,'2026-03-06 05:00:12.007');
INSERT INTO insights_raw VALUES(2,1,1,96,'2026-03-06 05:00:12.007');
INSERT INTO insights_raw VALUES(3,1,3,1,'2026-03-06 05:07:04.450');
INSERT INTO insights_raw VALUES(4,1,1,39,'2026-03-06 05:07:04.450');
CREATE TABLE IF NOT EXISTS "insights_by_period" ("id" integer PRIMARY KEY NOT NULL, "metaId" integer NOT NULL, "type" integer NOT NULL, "value" bigint NOT NULL, "periodUnit" integer NOT NULL, "periodStart" datetime(0) DEFAULT (CURRENT_TIMESTAMP), CONSTRAINT "FK_e8881f2214df046dc2740260fe8" FOREIGN KEY ("metaId") REFERENCES "insights_metadata" ("metaId") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "oauth_clients" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar(255) NOT NULL, "redirectUris" text NOT NULL, "grantTypes" text NOT NULL, "clientSecret" varchar(255), "clientSecretExpiresAt" bigint, "tokenEndpointAuthMethod" varchar(255) NOT NULL DEFAULT ('none'), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')));
CREATE TABLE IF NOT EXISTS "oauth_access_tokens" ("token" varchar PRIMARY KEY NOT NULL, "clientId" varchar NOT NULL, "userId" varchar NOT NULL, CONSTRAINT "FK_78b26968132b7e5e45b75876481" FOREIGN KEY ("clientId") REFERENCES "oauth_clients" ("id") ON DELETE CASCADE, CONSTRAINT "FK_7234a36d8e49a1fa85095328845" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "oauth_refresh_tokens" ("token" varchar(255) PRIMARY KEY NOT NULL, "clientId" varchar NOT NULL, "userId" varchar NOT NULL, "expiresAt" bigint NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_b388696ce4d8be7ffbe8d3e4b69" FOREIGN KEY ("clientId") REFERENCES "oauth_clients" ("id") ON DELETE CASCADE, CONSTRAINT "FK_a699f3ed9fd0c1b19bc2608ac53" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "oauth_user_consents" ("id" integer PRIMARY KEY NOT NULL, "userId" varchar NOT NULL, "clientId" varchar NOT NULL, "grantedAt" bigint NOT NULL, CONSTRAINT "UQ_083721d99ce8db4033e2958ebb4" UNIQUE ("userId", "clientId"), CONSTRAINT "FK_a651acea2f6c97f8c4514935486" FOREIGN KEY ("clientId") REFERENCES "oauth_clients" ("id") ON DELETE CASCADE, CONSTRAINT "FK_21e6c3c2d78a097478fae6aaefa" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "workflow_history" ("versionId" varchar(36) PRIMARY KEY NOT NULL, "workflowId" varchar(36) NOT NULL, "authors" varchar(255) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "nodes" text NOT NULL, "connections" text NOT NULL, "name" varchar(128), "autosaved" boolean NOT NULL DEFAULT (false), "description" text, CONSTRAINT "FK_1e31657f5fe46816c34be7c1b4b" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION);
INSERT INTO workflow_history VALUES('ca712434-0ad0-4d4f-8652-9eb9306ee2a8','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 04:58:21.686','2026-03-06 04:58:21.686','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-48,-96],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[256,-96],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[560,-96],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[816,-96],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('370acd9f-8c23-404f-be77-ec179f6ec858','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 04:58:28.731','2026-03-06 04:59:39','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}}','Version 370acd9f',1,'');
INSERT INTO workflow_history VALUES('baa86904-c4ef-4010-bb23-0d0798d02cbc','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 04:59:52.501','2026-03-06 04:59:52.501','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[512,224],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('81920a61-a843-4304-825d-75d8b5a9f3b3','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 04:59:56.071','2026-03-06 04:59:56.071','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('f2a17289-ca75-4511-a9b7-2691b7ce0fa3','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:00:01.003','2026-03-06 05:00:01.003','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nconst cmd = `docker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label traefik.http.routers.n8n-${user}.rule=Host(\\`${domain}\\`) \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${domain}` } }];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('fc3bc306-cf91-4f89-aa4b-75ee88a0be50','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:01:34.809','2026-03-06 05:01:34.809','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('285f3e29-532e-4e7c-b4b2-d193af9c54e5','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:02:48.475','2026-03-06 05:02:48.475','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('ee251927-8041-419f-97d4-a97f32049f96','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:11.200','2026-03-06 05:05:11.200','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('4fbe9afd-8972-4eb3-b6e1-bb70468b1e25','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:16.126','2026-03-06 05:05:16.126','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('36d1509a-6676-4676-b4eb-fe32fb63cc67','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:20.470','2026-03-06 05:05:20.470','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"009b5a49-b88a-4314-a3f1-89ed6eeffe93","name":"Webhook3","type":"n8n-nodes-base.webhook","position":[-976,1856],"typeVersion":1,"webhookId":"459de9ca-eec6-4e95-a7d0-772d0f1a514b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"6447f14c-cc00-4a41-8984-9cf0b0cfa3bb","name":"Prepare Data1","type":"n8n-nodes-base.function","position":[-736,1856],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"419de9af-19c1-4320-9542-ee2115dbb85e","name":"List Containers1","type":"n8n-nodes-base.executeCommand","position":[-480,1744],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"3ffadfe2-a97f-4184-94c4-b781fea47500","name":"Check Duplicate1","type":"n8n-nodes-base.function","position":[-224,1744],"typeVersion":1},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"fea1e447-d596-4039-9e60-cc9de087c024","name":"Build Docker Command2","type":"n8n-nodes-base.function","position":[32,1856],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"63857df6-328c-4324-84d8-87cf6168a149","name":"Run Docker2","type":"n8n-nodes-base.executeCommand","position":[272,1856],"typeVersion":1},{"parameters":{"options":{}},"id":"2a3d9c0d-7f65-4730-9f75-2ffe7f4543dc","name":"Respond3","type":"n8n-nodes-base.respondToWebhook","position":[528,1856],"typeVersion":1}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]},"Webhook3":{"main":[[{"node":"Prepare Data1","type":"main","index":0}]]},"Check Duplicate1":{"main":[[{"node":"Build Docker Command2","type":"main","index":0}]]},"Build Docker Command2":{"main":[[{"node":"Run Docker2","type":"main","index":0}]]},"Run Docker2":{"main":[[{"node":"Respond3","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('65eb6a08-e946-4793-ba82-6f40e7b8fabc','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:25.409','2026-03-06 05:05:25.409','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('4bf2016d-9c08-4a74-afca-1926ffdabfc7','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:40.654','2026-03-06 05:05:40.654','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"path":"ec0fa388-5055-4524-9adb-21dfd976f806","options":{}},"type":"n8n-nodes-base.webhook","typeVersion":2.1,"position":[-592,1664],"id":"84346f4e-5a9e-468d-b564-74fe7c1e8c99","name":"Webhook3","webhookId":"ec0fa388-5055-4524-9adb-21dfd976f806"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('36a5005f-c69a-434c-a24f-63076b19735b','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:46.085','2026-03-06 05:05:46.085','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('fc47ad8e-caf4-428e-a45a-8e8a7bd70196','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:50.825','2026-03-06 05:05:50.825','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('31cf9688-316a-4cc4-a8df-ba01116bebf5','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:05:54.460','2026-03-06 05:05:54.460','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user1"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('7be55d5f-51fe-48da-b0cb-d3842ba563fe','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:06:06.652','2026-03-06 05:06:06.652','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[112,-144],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973"},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user1"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('ba231745-44b2-4e08-86f0-0dc5ea19589d','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:06:17.639','2026-03-06 05:06:17.639','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b"},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user1"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('9d185630-6aca-46e3-b9b4-7ceb8e19d3fb','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:06:27.147','2026-03-06 05:06:29','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user1"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}','Version 9d185630',1,'');
INSERT INTO workflow_history VALUES('12245b43-f693-48fc-9f02-fb1e6f96050f','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:06:40.633','2026-03-06 05:06:40.633','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user1"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('4feebac7-ff3b-4bf3-839a-9d6a02c3a16e','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:06:44.417','2026-03-06 05:06:44.417','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('bfa0341d-c9ac-4770-8935-19b9c2979780','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:06:49.522','2026-03-06 05:06:49.522','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('c4d8b9a6-f94e-472b-96a8-34466617b949','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:10:23.032','2026-03-06 05:10:23.032','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = ;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('b0319ad9-feaa-4e2d-a01f-87c1bdedcec8','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:11:17.086','2026-03-06 05:11:17.086','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = ;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"},{"parameters":{"jsCode":"// Loop over input items and add a new field called ''myNewField'' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-464,1200],"id":"48594458-80cf-442a-be1d-c146a406d631","name":"Code in JavaScript"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0},{"node":"Code in JavaScript","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('3763d912-8e4d-42ae-95c0-5756b67cad5e','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:11:20.910','2026-03-06 05:11:20.910','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":"const user = ;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"},{"parameters":{"jsCode":"// Loop over input items and add a new field called ''myNewField'' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-464,1200],"id":"48594458-80cf-442a-be1d-c146a406d631","name":"Code in JavaScript"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('af3173d0-d5a2-4e82-8080-9dc9eb1a5638','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:11:24.773','2026-03-06 05:11:24.773','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":""},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"},{"parameters":{"jsCode":"// Loop over input items and add a new field called ''myNewField'' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-464,1200],"id":"48594458-80cf-442a-be1d-c146a406d631","name":"Code in JavaScript"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('44117e37-f6ac-4327-93f8-eb439bd1a09c','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:11:31.532','2026-03-06 05:11:31.532','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":""},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"},{"parameters":{"jsCode":"const user = ;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-464,1200],"id":"48594458-80cf-442a-be1d-c146a406d631","name":"Code in JavaScript"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
INSERT INTO workflow_history VALUES('91ac832d-df1a-46ee-87ad-0aa740ed9f86','ioR8eFBEVaKOkjc0','RIZOWAN rizowansiddique@gmail.com','2026-03-06 05:11:38.177','2026-03-06 05:11:38.177','[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":""},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"},{"parameters":{"jsCode":"const user = ;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-480,1312],"id":"48594458-80cf-442a-be1d-c146a406d631","name":"Code in JavaScript"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}',NULL,1,NULL);
CREATE TABLE IF NOT EXISTS "workflow_entity" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(128) NOT NULL, "active" boolean NOT NULL, "nodes" text, "connections" text, "settings" text, "staticData" text, "pinData" text, "versionId" varchar(36) NOT NULL, "triggerCount" integer DEFAULT (0), "meta" text, "parentFolderId" varchar(36), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "isArchived" boolean NOT NULL DEFAULT (FALSE), "versionCounter" integer NOT NULL DEFAULT (1), "description" text, "activeVersionId" varchar(36), CONSTRAINT "FK_04a4db5906fbc5606c71448d912" FOREIGN KEY ("parentFolderId") REFERENCES "folder" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_08d6c67b7f722b0039d9d5ed620" FOREIGN KEY ("activeVersionId") REFERENCES "workflow_history" ("versionId") ON DELETE RESTRICT);
INSERT INTO workflow_entity VALUES('ioR8eFBEVaKOkjc0','Create n8n Instance',1,'[{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook","type":"n8n-nodes-base.webhook","position":[-192,-144],"typeVersion":1,"id":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","webhookId":"a4d792e3-b5b9-425f-b612-c938e71de65d"},{"parameters":{"functionCode":"const user = $json.user_id;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = \"n8n.\" + user + \".inmetech.cloud\";\n\nconst cmd = `\ndocker run -d \\\n--name n8n-${user} \\\n--memory=${ram} \\\n--cpus=${cpu} \\\n-v n8n_${user}:/home/node/.n8n \\\n-e N8N_HOST=${domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \"traefik.http.routers.n8n-${user}.rule=Host(''${domain}'')\" \\\n--label traefik.http.routers.n8n-${user}.entrypoints=websecure \\\n--label traefik.http.routers.n8n-${user}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.n8n-${user}.loadbalancer.server.port=5678 \\\ndocker.n8n.io/n8nio/n8n\n`;\n\nreturn [{\n  json: {\n    command: cmd,\n    url: \"https://\" + domain\n  }\n}];"},"name":"Build Docker Command","type":"n8n-nodes-base.function","position":[176,-192],"typeVersion":1,"id":"7c91468e-80ea-4de5-8553-376dc01f0973","disabled":true},{"parameters":{"command":"={{$json.command}}"},"name":"Run Docker","type":"n8n-nodes-base.executeCommand","position":[416,-144],"typeVersion":1,"id":"d049c848-745f-43ce-ad8f-2069344eb356"},{"parameters":{"options":{}},"name":"Respond","type":"n8n-nodes-base.respondToWebhook","position":[672,-144],"typeVersion":1,"id":"c17c8373-bb00-4562-ae8f-c18a13839f0d"},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"user123"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[336,-400],"id":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","name":"HTTP Request"},{"parameters":{"values":{"string":[{"name":"apiKey","value":"{{$json[\"apiKey\"] || $env.API_KEY || \"\"}}"},{"name":"username","value":"={{$json[\"username\"] || $json[\"email\"] || $json[\"user\"] || \"user\"}}"},{"name":"plan","value":"={{$json[\"plan\"] || \"basic\"}}"},{"name":"domain","value":"={{$json[\"domain\"] || $env.DEFAULT_DOMAIN || \"inmetech.cloud\"}}"}]},"options":{}},"name":"Set Input","type":"n8n-nodes-base.set","typeVersion":1,"position":[-400,256],"id":"503fad3f-a1b5-4820-a049-48dd916574f5"},{"parameters":{"functionCode":"const payload = items[0].json;\n\n// simple API key check (secure your webhook in production)\nconst providedKey = payload.apiKey || '''';\nconst expected = process.env.API_KEY || '''';\nif (!expected || providedKey !== expected) {\n  throw new Error(''Invalid API key'');\n}\n\n// sanitize username\nlet raw = (payload.username || ''user'').toString();\nlet username = raw.toLowerCase().replace(/[^a-z0-9\\-]/g, '''').slice(0, 20) || ''user'';\n\n// plan -> resources mapping (restrict to allowed values)\nconst plans = {\n  basic: { ram: ''1g'', cpus: ''0.5'' },\n  pro: { ram: ''2g'', cpus: ''1'' },\n  agency: { ram: ''4g'', cpus: ''2'' }\n};\nconst plan = (payload.plan || ''basic'').toLowerCase();\nconst res = plans[plan] || plans[''basic''];\n\nconst domain = (payload.domain || process.env.DEFAULT_DOMAIN || ''inmetech.cloud'').replace(/[^a-z0-9.\\-]/gi,'''');\nconst subdomain = `n8n-${username}`;\nconst host = `${subdomain}.${domain}`;\nconst containerName = `n8n-${username}`;\nconst volume = `${containerName}_data`;\n\n// environment variables for each user container (disable dangerous nodes for clients)\nconst envs = [\n  `-e N8N_HOST=${host}`,\n  `-e N8N_PROTOCOL=https`,\n  `-e WEBHOOK_URL=https://${host}/` ,\n  `-e N8N_TRUST_PROXY=true`,\n  `-e N8N_SECURE_COOKIE=true`,\n  `-e NODES_EXCLUDE=[\"n8n-nodes-base.executeCommand\",\"n8n-nodes-base.localFileTrigger\"]`\n];\n\n// labels for Traefik routing\nconst labels = [\n  `--label traefik.enable=true`,\n  `--label traefik.http.routers.${containerName}.entrypoints=websecure`,\n  `--label traefik.http.routers.${containerName}.rule=Host(\\`${host}\\`)`,\n  `--label traefik.http.routers.${containerName}.tls.certresolver=letsencrypt`,\n  `--label traefik.http.services.${containerName}.loadbalancer.server.port=5678`\n];\n\n// prepare docker commands\nconst cmdCreateVolume = `docker volume create ${volume}`;\nconst cmdRun = `docker run -d --name ${containerName} --restart unless-stopped --memory=${res.ram} --cpus=${res.cpus} -v ${volume}:/home/node/.n8n ${envs.join('' '')} ${labels.join('' '')} docker.n8n.io/n8nio/n8n`;\n\n// check existing container cmd\nconst cmdCheck = `docker ps -a --filter \\\"name=^/${containerName}$\\\" --format \\\"{{.Names}}\\\"`;\n\nreturn [ { json: { username, plan, domain, host, containerName, cmdCreateVolume, cmdRun, cmdCheck } } ];"},"name":"Build Commands","type":"n8n-nodes-base.function","typeVersion":1,"position":[-160,256],"id":"6b4138b5-495d-46a4-8a37-1ef01adb601a"},{"parameters":{"command":"={{$json.commandCheck}}"},"name":"Check Existing","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,192],"id":"33050773-1166-410e-af9a-2629b205483c"},{"parameters":{"functionCode":"const out = items[0].json;\nif (out && out.data && out.data.length) {\n  const names = out.data.trim();\n  if (names) throw new Error(`Container already exists: ${names}`);\n}\nreturn items;"},"name":"Fail If Exists","type":"n8n-nodes-base.function","typeVersion":1,"position":[336,192],"id":"8b770345-6008-45df-b449-648dc9181903"},{"parameters":{"command":"={{$json.cmdCreateVolume}}"},"name":"Create Volume","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[96,320],"id":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621"},{"parameters":{"command":"={{$json.cmdRun}}"},"name":"Run Container","type":"n8n-nodes-base.executeCommand","typeVersion":1,"position":[336,320],"id":"749ef316-deab-4898-805c-891900d0fed0"},{"parameters":{"functionCode":"const j = items[0].json;\nreturn [{ json: { success: true, host: j.host, container: j.containerName, message: ''Container creation triggered. Allow 10-30s to boot and acquire TLS.'' } }];"},"name":"Prepare Response","type":"n8n-nodes-base.function","typeVersion":1,"position":[608,256],"id":"352f91c6-e900-433c-8d9b-b653cbf5e275"},{"parameters":{"httpMethod":"POST","path":"create-n8n","options":{}},"name":"Webhook1","type":"n8n-nodes-base.webhook","typeVersion":1,"position":[-640,256],"id":"8e72c500-0d98-4892-b3bf-16633ffdb18f","webhookId":"91e8d5c0-cb20-4d3a-978a-db8e22e4073b","disabled":true},{"parameters":{"options":{}},"name":"Respond1","type":"n8n-nodes-base.respondToWebhook","typeVersion":1,"position":[864,256],"id":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b"},{"parameters":{"functionCode":""},"id":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","name":"Prepare Data","type":"n8n-nodes-base.function","position":[-672,1200],"typeVersion":1},{"parameters":{"command":"docker ps -a --format ''{{.Names}}''"},"id":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","name":"List Containers","type":"n8n-nodes-base.executeCommand","position":[-416,1088],"typeVersion":1},{"parameters":{"functionCode":"const existing = $json.stdout || \"\";\nconst user = $items(\"Prepare Data\")[0].json.user;\n\nif (existing.includes(`n8n-${user}`)) {\n  throw new Error(\"Container already exists\");\n}\n\nreturn $items(\"Prepare Data\");"},"id":"12aa3069-ada6-4845-ad2f-87af3d31bb85","name":"Check Duplicate","type":"n8n-nodes-base.function","position":[-160,1088],"typeVersion":1},{"parameters":{"httpMethod":"POST","path":"create-n8n1111","options":{}},"id":"fb6697e6-8815-4beb-936d-f16f1814cfdc","name":"Webhook2","type":"n8n-nodes-base.webhook","position":[-912,1200],"typeVersion":1,"webhookId":"c08aedad-597e-4ea4-b647-bccecb2c90f3"},{"parameters":{"functionCode":"const data = $json;\n\nconst cmd = `docker run -d \\\n--name ${data.container} \\\n--memory=${data.ram} \\\n--cpus=${data.cpu} \\\n-v ${data.volume}:/home/node/.n8n \\\n-e N8N_HOST=${data.domain} \\\n-e N8N_PROTOCOL=https \\\n-e WEBHOOK_URL=https://${data.domain}/ \\\n-e N8N_TRUST_PROXY=true \\\n--label traefik.enable=true \\\n--label \\\"traefik.http.routers.${data.container}.rule=Host(''${data.domain}'')\\\" \\\n--label traefik.http.routers.${data.container}.entrypoints=websecure \\\n--label traefik.http.routers.${data.container}.tls.certresolver=letsencrypt \\\n--label traefik.http.services.${data.container}.loadbalancer.server.port=5678 \\\n docker.n8n.io/n8nio/n8n`;\n\nreturn [{ json: { command: cmd, url: `https://${data.domain}` } }];"},"id":"36f16652-730e-4ff9-8978-16747fa1d8e3","name":"Build Docker Command1","type":"n8n-nodes-base.function","position":[96,1200],"typeVersion":1},{"parameters":{"command":"={{$json.command}}"},"id":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","name":"Run Docker1","type":"n8n-nodes-base.executeCommand","position":[336,1200],"typeVersion":1},{"parameters":{"options":{}},"id":"2672e437-0f80-43fa-91ad-80805b69d424","name":"Respond2","type":"n8n-nodes-base.respondToWebhook","position":[592,1200],"typeVersion":1},{"parameters":{"method":"POST","url":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","sendBody":true,"bodyParameters":{"parameters":[{"name":"user_id","value":"1234"},{"name":"ram","value":"1g"},{"name":"cpu","value":"1"}]},"options":{}},"type":"n8n-nodes-base.httpRequest","typeVersion":4.4,"position":[-592,1664],"id":"6699443d-0372-4cbf-958a-e890a12c5381","name":"HTTP Request1"},{"parameters":{"jsCode":"const user = ;\n\nif (!user) {\n  throw new Error(\"user_id missing\");\n}\n\nconst ram = $json.ram || \"1g\";\nconst cpu = $json.cpu || \"1\";\n\nconst domain = `n8n.${user}.inmetech.cloud`;\n\nreturn [{\n  json: {\n    user,\n    ram,\n    cpu,\n    domain,\n    container: `n8n-${user}`,\n    volume: `n8n_${user}`\n  }\n}];"},"type":"n8n-nodes-base.code","typeVersion":2,"position":[-464,1200],"id":"48594458-80cf-442a-be1d-c146a406d631","name":"Code in JavaScript"}]','{"Webhook":{"main":[[{"node":"Build Docker Command","type":"main","index":0}]]},"Build Docker Command":{"main":[[{"node":"Run Docker","type":"main","index":0}]]},"Run Docker":{"main":[[{"node":"Respond","type":"main","index":0}]]},"Set Input":{"main":[[{"node":"Build Commands","type":"main","index":0}]]},"Build Commands":{"main":[[{"node":"Check Existing","type":"main","index":0},{"node":"Create Volume","type":"main","index":0}]]},"Check Existing":{"main":[[{"node":"Fail If Exists","type":"main","index":0}]]},"Fail If Exists":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Create Volume":{"main":[[{"node":"Run Container","type":"main","index":0}]]},"Run Container":{"main":[[{"node":"Prepare Response","type":"main","index":0}]]},"Prepare Response":{"main":[[{"node":"Respond1","type":"main","index":0}]]},"Webhook1":{"main":[[{"node":"Set Input","type":"main","index":0}]]},"Check Duplicate":{"main":[[{"node":"Build Docker Command1","type":"main","index":0}]]},"Webhook2":{"main":[[{"node":"Prepare Data","type":"main","index":0}]]},"Build Docker Command1":{"main":[[{"node":"Run Docker1","type":"main","index":0}]]},"Run Docker1":{"main":[[{"node":"Respond2","type":"main","index":0}]]},"Prepare Data":{"main":[[{"node":"List Containers","type":"main","index":0}]]},"List Containers":{"main":[[{"node":"Check Duplicate","type":"main","index":0}]]}}','{"executionOrder":"v1","binaryMode":"separate","availableInMCP":false}',NULL,'{"Webhook":[{"json":{"headers":{"host":"admin.n8n.inmetech.cloud","user-agent":"axios/1.13.5","content-length":"42","accept":"application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","accept-encoding":"gzip, compress, deflate, br","content-type":"application/json","x-forwarded-for":"172.18.0.1","x-forwarded-host":"admin.n8n.inmetech.cloud","x-forwarded-port":"443","x-forwarded-proto":"https","x-forwarded-server":"f431cf187979","x-real-ip":"172.18.0.1"},"params":{},"query":{},"body":{"user_id":"user123","ram":"1g","cpu":"1"},"webhookUrl":"https://admin.n8n.inmetech.cloud/webhook/create-n8n","executionMode":"production"},"pairedItem":{"item":0}}],"Webhook2":[{"json":{"headers":{"host":"admin.n8n.inmetech.cloud","user-agent":"axios/1.13.5","content-length":"39","accept":"application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7","accept-encoding":"gzip, compress, deflate, br","content-type":"application/json","x-forwarded-for":"172.18.0.1","x-forwarded-host":"admin.n8n.inmetech.cloud","x-forwarded-port":"443","x-forwarded-proto":"https","x-forwarded-server":"f431cf187979","x-real-ip":"172.18.0.1"},"params":{},"query":{},"body":{"user_id":"1234","ram":"1g","cpu":"1"},"webhookUrl":"https://admin.n8n.inmetech.cloud/webhook/create-n8n1111","executionMode":"production"},"pairedItem":{"item":0}}]}','44117e37-f6ac-4327-93f8-eb439bd1a09c',2,NULL,NULL,'2026-03-06 04:58:21.680','2026-03-06 05:11:31.530',0,30,NULL,'9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
CREATE TABLE IF NOT EXISTS "oauth_authorization_codes" ("code" varchar(255) PRIMARY KEY NOT NULL, "clientId" varchar NOT NULL, "userId" varchar NOT NULL, "redirectUri" varchar NOT NULL, "codeChallenge" varchar NOT NULL, "codeChallengeMethod" varchar(255) NOT NULL, "expiresAt" bigint NOT NULL, "state" varchar, "used" boolean NOT NULL DEFAULT (false), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_81de58036895ccabf2214c6d99e" FOREIGN KEY ("clientId") REFERENCES "oauth_clients" ("id") ON DELETE CASCADE, CONSTRAINT "FK_e829ca1240b877f73fd5fab14a2" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "binary_data" ("fileId" varchar PRIMARY KEY NOT NULL, "sourceType" varchar(50) NOT NULL, "sourceId" varchar(255) NOT NULL, "data" blob NOT NULL, "mimeType" varchar(255), "fileName" varchar(255), "fileSize" integer NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "CHK_binary_data_sourceType" CHECK ("sourceType" IN ('execution', 'chat_message_attachment')));
CREATE TABLE IF NOT EXISTS "workflow_publish_history" ("id" integer PRIMARY KEY NOT NULL, "workflowId" varchar(36) NOT NULL, "versionId" varchar(36) NOT NULL, "event" varchar(36) NOT NULL, "userId" varchar, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "CHK_workflow_publish_history_event" CHECK ("event" IN ('activated', 'deactivated')), CONSTRAINT "FK_c01316f8c2d7101ec4fa9809267" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE, CONSTRAINT "FK_b4cfbc7556d07f36ca177f5e473" FOREIGN KEY ("versionId") REFERENCES "workflow_history" ("versionId") ON DELETE CASCADE, CONSTRAINT "FK_6eab5bd9eedabe9c54bd879fc40" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE SET NULL);
INSERT INTO workflow_publish_history VALUES(1,'ioR8eFBEVaKOkjc0','370acd9f-8c23-404f-be77-ec179f6ec858','activated','3f77e136-dc7a-4d58-8dc6-817cb2b88866','2026-03-06 04:59:39.278');
INSERT INTO workflow_publish_history VALUES(2,'ioR8eFBEVaKOkjc0','370acd9f-8c23-404f-be77-ec179f6ec858','deactivated','3f77e136-dc7a-4d58-8dc6-817cb2b88866','2026-03-06 05:06:29.582');
INSERT INTO workflow_publish_history VALUES(3,'ioR8eFBEVaKOkjc0','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb','activated','3f77e136-dc7a-4d58-8dc6-817cb2b88866','2026-03-06 05:06:29.595');
CREATE TABLE IF NOT EXISTS "project" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(255) NOT NULL, "type" varchar(36) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "icon" text, "description" varchar(512), "creatorId" varchar, CONSTRAINT "projects_creatorId_foreign" FOREIGN KEY ("creatorId") REFERENCES "user" ("id") ON DELETE SET NULL);
INSERT INTO project VALUES('cZz5fzaW49pCUs3C','RIZOWAN rizowansiddique@gmail.com <rizowansiddique@gmail.com>','personal','2026-03-06 04:57:51.085','2026-03-06 04:58:02.404',NULL,NULL,'3f77e136-dc7a-4d58-8dc6-817cb2b88866');
CREATE TABLE IF NOT EXISTS "dynamic_credential_resolver" ("id" varchar(16) PRIMARY KEY NOT NULL, "name" varchar(128) NOT NULL, "type" varchar(128) NOT NULL, "config" text NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')));
CREATE TABLE IF NOT EXISTS "credentials_entity" ("id" varchar(36) PRIMARY KEY NOT NULL, "name" varchar(128) NOT NULL, "data" text NOT NULL, "type" varchar(32) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "isManaged" boolean NOT NULL DEFAULT (0), "isGlobal" boolean NOT NULL DEFAULT (0), "isResolvable" boolean NOT NULL DEFAULT (false), "resolvableAllowFallback" boolean NOT NULL DEFAULT (false), "resolverId" varchar(16), CONSTRAINT "credentials_entity_resolverId_foreign" FOREIGN KEY ("resolverId") REFERENCES "dynamic_credential_resolver" ("id") ON DELETE SET NULL);
CREATE TABLE IF NOT EXISTS "chat_hub_messages" ("id" varchar PRIMARY KEY NOT NULL, "sessionId" varchar NOT NULL, "previousMessageId" varchar, "revisionOfMessageId" varchar, "retryOfMessageId" varchar, "type" varchar(16) NOT NULL, "name" varchar(128) NOT NULL, "content" text NOT NULL, "provider" varchar(16), "workflowId" varchar(36), "executionId" integer, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "agentId" varchar(36), "status" varchar(16) NOT NULL DEFAULT ('success'), "attachments" text, "model" VARCHAR(256), CONSTRAINT "FK_e22538eb50a71a17954cd7e076c" FOREIGN KEY ("sessionId") REFERENCES "chat_hub_sessions" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_e5d1fa722c5a8d38ac204746662" FOREIGN KEY ("previousMessageId") REFERENCES "chat_hub_messages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_acf8926098f063cdbbad8497fd1" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_25c9736e7f769f3a005eef4b372" FOREIGN KEY ("retryOfMessageId") REFERENCES "chat_hub_messages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_1f4998c8a7dec9e00a9ab15550e" FOREIGN KEY ("revisionOfMessageId") REFERENCES "chat_hub_messages" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_6afb260449dd7a9b85355d4e0c9" FOREIGN KEY ("executionId") REFERENCES "execution_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_chat_hub_messages_agentId" FOREIGN KEY ("agentId") REFERENCES "chat_hub_agents" ("id") ON DELETE SET NULL);
CREATE TABLE IF NOT EXISTS "workflow_statistics" (
				"id" INTEGER PRIMARY KEY AUTOINCREMENT,
				"count" INTEGER DEFAULT 0,
				"latestEvent" DATETIME,
				"name" VARCHAR(128) NOT NULL,
				"workflowId" VARCHAR(36) NOT NULL,
				"workflowName" VARCHAR(128),
				"rootCount" INTEGER DEFAULT 0
			);
INSERT INTO workflow_statistics VALUES(1,1,'2026-03-06 05:00:11.863','data_loaded','ioR8eFBEVaKOkjc0',NULL,1);
INSERT INTO workflow_statistics VALUES(2,2,'2026-03-06 05:07:04','manual_success','ioR8eFBEVaKOkjc0','Create n8n Instance',0);
INSERT INTO workflow_statistics VALUES(3,2,'2026-03-06 05:07:04','production_error','ioR8eFBEVaKOkjc0','Create n8n Instance',2);
INSERT INTO workflow_statistics VALUES(4,1,'2026-03-06 05:01:35','manual_error','ioR8eFBEVaKOkjc0','Create User n8n Server',0);
CREATE TABLE IF NOT EXISTS "dynamic_credential_user_entry" ("credentialId" varchar(16) NOT NULL, "userId" varchar NOT NULL, "resolverId" varchar(16) NOT NULL, "data" text NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_945ba70b342a066d1306b12ccd2" FOREIGN KEY ("credentialId") REFERENCES "credentials_entity" ("id") ON DELETE CASCADE, CONSTRAINT "FK_6edec973a6450990977bb854c38" FOREIGN KEY ("resolverId") REFERENCES "dynamic_credential_resolver" ("id") ON DELETE CASCADE, CONSTRAINT "FK_a36dc616fabc3f736bb82410a22" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE, PRIMARY KEY ("credentialId", "userId", "resolverId"));
CREATE TABLE IF NOT EXISTS "workflow_dependency" ("id" integer PRIMARY KEY NOT NULL, "workflowId" varchar(36) NOT NULL, "workflowVersionId" integer NOT NULL, "dependencyType" varchar(32) NOT NULL, "dependencyKey" varchar(255) NOT NULL, "indexVersionId" smallint NOT NULL DEFAULT (1), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "dependencyInfo" text, "publishedVersionId" varchar(36), CONSTRAINT "FK_a4ff2d9b9628ea988fa9e7d0bf8" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION);
INSERT INTO workflow_dependency VALUES(36,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.webhook',1,'2026-03-06 05:06:29.599','{"nodeId":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(37,'ioR8eFBEVaKOkjc0',21,'webhookPath','create-n8n',1,'2026-03-06 05:06:29.599','{"nodeId":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(38,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"7c91468e-80ea-4de5-8553-376dc01f0973","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(39,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:06:29.599','{"nodeId":"d049c848-745f-43ce-ad8f-2069344eb356","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(40,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.respondToWebhook',1,'2026-03-06 05:06:29.599','{"nodeId":"c17c8373-bb00-4562-ae8f-c18a13839f0d","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(41,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.httpRequest',1,'2026-03-06 05:06:29.599','{"nodeId":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","nodeVersion":4.4}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(42,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.set',1,'2026-03-06 05:06:29.599','{"nodeId":"503fad3f-a1b5-4820-a049-48dd916574f5","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(43,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"6b4138b5-495d-46a4-8a37-1ef01adb601a","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(44,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:06:29.599','{"nodeId":"33050773-1166-410e-af9a-2629b205483c","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(45,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"8b770345-6008-45df-b449-648dc9181903","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(46,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:06:29.599','{"nodeId":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(47,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:06:29.599','{"nodeId":"749ef316-deab-4898-805c-891900d0fed0","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(48,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"352f91c6-e900-433c-8d9b-b653cbf5e275","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(49,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.webhook',1,'2026-03-06 05:06:29.599','{"nodeId":"8e72c500-0d98-4892-b3bf-16633ffdb18f","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(50,'ioR8eFBEVaKOkjc0',21,'webhookPath','create-n8n',1,'2026-03-06 05:06:29.599','{"nodeId":"8e72c500-0d98-4892-b3bf-16633ffdb18f","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(51,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.respondToWebhook',1,'2026-03-06 05:06:29.599','{"nodeId":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(52,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(53,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:06:29.599','{"nodeId":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(54,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"12aa3069-ada6-4845-ad2f-87af3d31bb85","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(55,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.webhook',1,'2026-03-06 05:06:29.599','{"nodeId":"fb6697e6-8815-4beb-936d-f16f1814cfdc","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(56,'ioR8eFBEVaKOkjc0',21,'webhookPath','create-n8n1111',1,'2026-03-06 05:06:29.599','{"nodeId":"fb6697e6-8815-4beb-936d-f16f1814cfdc","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(57,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:06:29.599','{"nodeId":"36f16652-730e-4ff9-8978-16747fa1d8e3","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(58,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:06:29.599','{"nodeId":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(59,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.respondToWebhook',1,'2026-03-06 05:06:29.599','{"nodeId":"2672e437-0f80-43fa-91ad-80805b69d424","nodeVersion":1}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(60,'ioR8eFBEVaKOkjc0',21,'nodeType','n8n-nodes-base.httpRequest',1,'2026-03-06 05:06:29.599','{"nodeId":"6699443d-0372-4cbf-958a-e890a12c5381","nodeVersion":4.4}','9d185630-6aca-46e3-b9b4-7ceb8e19d3fb');
INSERT INTO workflow_dependency VALUES(61,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.webhook',1,'2026-03-06 05:11:31.544','{"nodeId":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(62,'ioR8eFBEVaKOkjc0',30,'webhookPath','create-n8n',1,'2026-03-06 05:11:31.544','{"nodeId":"026a9c89-93a9-4dc5-9af4-701d31b89ae6","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(63,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"7c91468e-80ea-4de5-8553-376dc01f0973","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(64,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:11:31.544','{"nodeId":"d049c848-745f-43ce-ad8f-2069344eb356","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(65,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.respondToWebhook',1,'2026-03-06 05:11:31.544','{"nodeId":"c17c8373-bb00-4562-ae8f-c18a13839f0d","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(66,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.httpRequest',1,'2026-03-06 05:11:31.544','{"nodeId":"9654e007-c6e7-4a2b-b48a-7ee7df40a1c0","nodeVersion":4.4}',NULL);
INSERT INTO workflow_dependency VALUES(67,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.set',1,'2026-03-06 05:11:31.544','{"nodeId":"503fad3f-a1b5-4820-a049-48dd916574f5","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(68,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"6b4138b5-495d-46a4-8a37-1ef01adb601a","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(69,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:11:31.544','{"nodeId":"33050773-1166-410e-af9a-2629b205483c","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(70,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"8b770345-6008-45df-b449-648dc9181903","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(71,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:11:31.544','{"nodeId":"c3ef5fcd-65be-44ef-a8fa-dc1db8dc1621","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(72,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:11:31.544','{"nodeId":"749ef316-deab-4898-805c-891900d0fed0","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(73,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"352f91c6-e900-433c-8d9b-b653cbf5e275","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(74,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.webhook',1,'2026-03-06 05:11:31.544','{"nodeId":"8e72c500-0d98-4892-b3bf-16633ffdb18f","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(75,'ioR8eFBEVaKOkjc0',30,'webhookPath','create-n8n',1,'2026-03-06 05:11:31.544','{"nodeId":"8e72c500-0d98-4892-b3bf-16633ffdb18f","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(76,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.respondToWebhook',1,'2026-03-06 05:11:31.544','{"nodeId":"8d30d07b-7c63-43dd-89cc-fed8ec9d226b","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(77,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"9ddf7ecd-9b82-40df-82c7-63fc748fb79c","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(78,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:11:31.544','{"nodeId":"0f259cf3-ccd1-481d-b237-bbb048f9ce3c","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(79,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"12aa3069-ada6-4845-ad2f-87af3d31bb85","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(80,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.webhook',1,'2026-03-06 05:11:31.544','{"nodeId":"fb6697e6-8815-4beb-936d-f16f1814cfdc","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(81,'ioR8eFBEVaKOkjc0',30,'webhookPath','create-n8n1111',1,'2026-03-06 05:11:31.544','{"nodeId":"fb6697e6-8815-4beb-936d-f16f1814cfdc","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(82,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.function',1,'2026-03-06 05:11:31.544','{"nodeId":"36f16652-730e-4ff9-8978-16747fa1d8e3","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(83,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.executeCommand',1,'2026-03-06 05:11:31.544','{"nodeId":"652ddbd1-09f1-4ac6-84c2-169a34d5016c","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(84,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.respondToWebhook',1,'2026-03-06 05:11:31.544','{"nodeId":"2672e437-0f80-43fa-91ad-80805b69d424","nodeVersion":1}',NULL);
INSERT INTO workflow_dependency VALUES(85,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.httpRequest',1,'2026-03-06 05:11:31.544','{"nodeId":"6699443d-0372-4cbf-958a-e890a12c5381","nodeVersion":4.4}',NULL);
INSERT INTO workflow_dependency VALUES(86,'ioR8eFBEVaKOkjc0',30,'nodeType','n8n-nodes-base.code',1,'2026-03-06 05:11:31.544','{"nodeId":"48594458-80cf-442a-be1d-c146a406d631","nodeVersion":2}',NULL);
CREATE TABLE IF NOT EXISTS "secrets_provider_connection" ("id" integer PRIMARY KEY NOT NULL, "providerKey" varchar(128) NOT NULL, "type" varchar(36) NOT NULL, "encryptedSettings" text NOT NULL, "isEnabled" boolean NOT NULL DEFAULT (false), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')));
CREATE TABLE IF NOT EXISTS "dynamic_credential_entry" ("credential_id" varchar(16) NOT NULL, "subject_id" varchar(2048) NOT NULL, "resolver_id" varchar(16) NOT NULL, "data" text NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_a6d1dd080958304a47a02952aab" FOREIGN KEY ("credential_id") REFERENCES "credentials_entity" ("id") ON DELETE CASCADE, CONSTRAINT "FK_d61a12235d268a49af6a3c09c13" FOREIGN KEY ("resolver_id") REFERENCES "dynamic_credential_resolver" ("id") ON DELETE CASCADE, PRIMARY KEY ("credential_id", "subject_id", "resolver_id"));
CREATE TABLE IF NOT EXISTS "chat_hub_tools" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar(255) NOT NULL, "type" varchar(255) NOT NULL, "typeVersion" real NOT NULL, "ownerId" varchar NOT NULL, "definition" text NOT NULL, "enabled" boolean NOT NULL DEFAULT (true), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_b8030b47af9213f1fd15450fb7f" FOREIGN KEY ("ownerId") REFERENCES "user" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "chat_hub_session_tools" ("sessionId" varchar NOT NULL, "toolId" varchar NOT NULL, CONSTRAINT "FK_e649bf1295f4ed8d4299ed290f9" FOREIGN KEY ("sessionId") REFERENCES "chat_hub_sessions" ("id") ON DELETE CASCADE, CONSTRAINT "FK_6596a328affd8d4967ffb303eee" FOREIGN KEY ("toolId") REFERENCES "chat_hub_tools" ("id") ON DELETE CASCADE, PRIMARY KEY ("sessionId", "toolId"));
CREATE TABLE IF NOT EXISTS "chat_hub_agent_tools" ("agentId" varchar NOT NULL, "toolId" varchar NOT NULL, CONSTRAINT "FK_2b53d796b3dbae91b1a9553c048" FOREIGN KEY ("agentId") REFERENCES "chat_hub_agents" ("id") ON DELETE CASCADE, CONSTRAINT "FK_43e70f04c53344f82483d0570f6" FOREIGN KEY ("toolId") REFERENCES "chat_hub_tools" ("id") ON DELETE CASCADE, PRIMARY KEY ("agentId", "toolId"));
CREATE TABLE IF NOT EXISTS "workflow_builder_session" ("id" varchar PRIMARY KEY NOT NULL, "workflowId" varchar(36) NOT NULL, "userId" varchar NOT NULL, "messages" text NOT NULL DEFAULT ('[]'), "previousSummary" text, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "UQ_ec2aa73632932d485a1d5192ce1" UNIQUE ("workflowId", "userId"), CONSTRAINT "FK_7983c618db48f47bf5a4cc1e1e4" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE, CONSTRAINT "FK_00290cdeee4d4d7db84709be936" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE);
CREATE TABLE IF NOT EXISTS "chat_hub_agents" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar(256) NOT NULL, "description" varchar(512), "systemPrompt" text NOT NULL, "ownerId" varchar NOT NULL, "credentialId" varchar(36), "provider" varchar(16) NOT NULL, "model" varchar(64) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "icon" text, "files" text NOT NULL DEFAULT ('[]'), "suggestedPrompts" text NOT NULL DEFAULT ('[]'), CONSTRAINT "FK_441ba2caba11e077ce3fbfa2cd8" FOREIGN KEY ("ownerId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_9c61ad497dcbae499c96a6a78ba" FOREIGN KEY ("credentialId") REFERENCES "credentials_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION);
CREATE TABLE IF NOT EXISTS "project_secrets_provider_access" ("secretsProviderConnectionId" integer NOT NULL, "projectId" varchar(36) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "role" varchar(128) NOT NULL DEFAULT ('secretsProviderConnection:user'), CONSTRAINT "CHK_project_secrets_provider_access_role" CHECK ("role" IN ('secretsProviderConnection:owner', 'secretsProviderConnection:user')), CONSTRAINT "FK_bd264b81209355b543878deedb1" FOREIGN KEY ("projectId") REFERENCES "project" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_18e5c27d2524b1638b292904e48" FOREIGN KEY ("secretsProviderConnectionId") REFERENCES "secrets_provider_connection" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, PRIMARY KEY ("secretsProviderConnectionId", "projectId"));
CREATE TABLE IF NOT EXISTS "workflow_published_version" ("workflowId" varchar(36) PRIMARY KEY NOT NULL, "publishedVersionId" varchar(36) NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "FK_df3428a541b802d6a63ac56e330" FOREIGN KEY ("publishedVersionId") REFERENCES "workflow_history" ("versionId") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_5c76fb7ee939fe2530374d3f75a" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_5c76fb7ee939fe2530374d3f75a" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE RESTRICT, CONSTRAINT "FK_df3428a541b802d6a63ac56e330" FOREIGN KEY ("publishedVersionId") REFERENCES "workflow_history" ("versionId") ON DELETE RESTRICT);
CREATE TABLE IF NOT EXISTS "chat_hub_sessions" ("id" varchar PRIMARY KEY NOT NULL, "title" varchar(256) NOT NULL, "ownerId" varchar NOT NULL, "lastMessageAt" datetime(3) NOT NULL, "credentialId" varchar(36), "provider" varchar(16), "model" varchar(64), "workflowId" varchar(36), "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "updatedAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), "agentId" varchar(36), "agentName" varchar(128), "type" varchar(16) NOT NULL DEFAULT ('production'), CONSTRAINT "CHK_chat_hub_sessions_type" CHECK ("type" IN ('production', 'manual')), CONSTRAINT "FK_e9ecf8ede7d989fcd18790fe36a" FOREIGN KEY ("ownerId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_7bc13b4c7e6afbfaf9be326c189" FOREIGN KEY ("credentialId") REFERENCES "credentials_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_9f9293d9f552496c40e0d1a8f80" FOREIGN KEY ("workflowId") REFERENCES "workflow_entity" ("id") ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT "FK_chat_hub_sessions_agentId" FOREIGN KEY ("agentId") REFERENCES "chat_hub_agents" ("id") ON DELETE SET NULL ON UPDATE NO ACTION);
DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES('migrations',148);
INSERT INTO sqlite_sequence VALUES('execution_metadata',0);
INSERT INTO sqlite_sequence VALUES('execution_entity',5);
INSERT INTO sqlite_sequence VALUES('workflow_statistics',6);
CREATE TRIGGER workflow_version_increment
			AFTER UPDATE ON workflow_entity
			FOR EACH ROW
			WHEN OLD."versionCounter" = NEW."versionCounter"
			BEGIN
				UPDATE workflow_entity
				SET "versionCounter" = "versionCounter" + 1
				WHERE id = NEW.id;
			END;
CREATE INDEX "idx_workflows_tags_tag_id" ON "workflows_tags" ("tagId");
CREATE INDEX "idx_workflows_tags_workflow_id" ON "workflows_tags" ("workflowId");
CREATE INDEX "idx_webhook_entity_webhook_path_method" ON "webhook_entity" ("webhookId","method","pathLength");
CREATE UNIQUE INDEX "IDX_8f949d7a3a984759044054e89b" ON "tag_entity" ("name") ;
CREATE UNIQUE INDEX "IDX_cec8eea3bf49551482ccb4933e" ON "execution_metadata" ("executionId", "key") ;
CREATE UNIQUE INDEX "IDX_97f863fa83c4786f1956508496" ON "execution_annotations" ("executionId") ;
CREATE UNIQUE INDEX "IDX_ae51b54c4bb430cf92f48b623f" ON "annotation_tag_entity" ("name") ;
CREATE INDEX "IDX_a3697779b366e131b2bbdae297" ON "execution_annotation_tags" ("tagId") ;
CREATE INDEX "IDX_c1519757391996eb06064f0e7c" ON "execution_annotation_tags" ("annotationId") ;
CREATE INDEX "IDX_execution_entity_stoppedAt" ON "execution_entity" ("stoppedAt") ;
CREATE INDEX "IDX_execution_entity_deletedAt" ON "execution_entity" ("deletedAt") ;
CREATE UNIQUE INDEX "IDX_14f68deffaf858465715995508" ON "folder" ("projectId", "id") ;
CREATE UNIQUE INDEX "IDX_1d8ab99d5861c9388d2dc1cf73" ON "insights_metadata" ("workflowId") ;
CREATE INDEX "IDX_d6870d3b6e4c185d33926f423c" ON "test_run" ("workflowId") ;
CREATE INDEX "IDX_role_scope_scopeSlug" ON "role_scope" ("scopeSlug") ;
CREATE INDEX "IDX_8e4b4774db42f1e6dda3452b2a" ON "test_case_execution" ("testRunId") ;
CREATE INDEX "IDX_5f0643f6717905a05164090dde" ON "project_relation" ("userId") ;
CREATE INDEX "IDX_61448d56d61802b5dfde5cdb00" ON "project_relation" ("projectId") ;
CREATE INDEX "project_relation_role_idx" ON "project_relation" ("role") ;
CREATE INDEX "project_relation_role_project_idx" ON "project_relation" ("projectId", "role") ;
CREATE INDEX "user_role_idx" ON "user" ("roleSlug") ;
CREATE UNIQUE INDEX "variables_project_key_unique" ON "variables" ("projectId", "key") ;
CREATE UNIQUE INDEX "variables_global_key_unique"
			 ON "variables" ("key")
			 WHERE projectId IS NULL;
CREATE UNIQUE INDEX "IDX_a4da41795da1422f680c723e80" ON "insights_by_period" ("periodStart", "type", "periodUnit", "metaId") ;
CREATE UNIQUE INDEX "IDX_UniqueRoleDisplayName" ON "role" ("displayName");
CREATE INDEX "IDX_1e31657f5fe46816c34be7c1b4" ON "workflow_history" ("workflowId") ;
CREATE INDEX "IDX_e10425f6ab9964c4c1623a4a03" ON "workflow_entity" ("name") ;
CREATE INDEX "IDX_56900edc3cfd16612e2ef2c6a8" ON "binary_data" ("sourceType", "sourceId") ;
CREATE INDEX "IDX_070b5de842ece9ccdda0d9738b" ON "workflow_publish_history" ("workflowId", "versionId") ;
CREATE INDEX "IDX_9c9ee9df586e60bb723234e499" ON "dynamic_credential_resolver" ("type") ;
CREATE INDEX "idx_credentials_entity_type" ON "credentials_entity" ("type") ;
CREATE INDEX "IDX_chat_hub_messages_sessionId"
			ON "chat_hub_messages"("sessionId");
CREATE UNIQUE INDEX "IDX_workflow_statistics_workflow_name" ON "workflow_statistics" ("workflowId", "name");
CREATE INDEX "IDX_a36dc616fabc3f736bb82410a2" ON "dynamic_credential_user_entry" ("userId") ;
CREATE INDEX "IDX_6edec973a6450990977bb854c3" ON "dynamic_credential_user_entry" ("resolverId") ;
CREATE INDEX "IDX_e48a201071ab85d9d09119d640" ON "workflow_dependency" ("dependencyKey") ;
CREATE INDEX "IDX_e7fe1cfda990c14a445937d0b9" ON "workflow_dependency" ("dependencyType") ;
CREATE INDEX "IDX_a4ff2d9b9628ea988fa9e7d0bf" ON "workflow_dependency" ("workflowId") ;
CREATE INDEX "IDX_workflow_dependency_publishedVersionId" ON "workflow_dependency" ("publishedVersionId") ;
CREATE UNIQUE INDEX "IDX_secrets_provider_connection_providerKey" ON "secrets_provider_connection" ("providerKey") ;
CREATE INDEX "IDX_62476b94b56d9dc7ed9ed75d3d" ON "dynamic_credential_entry" ("subject_id") ;
CREATE INDEX "IDX_d61a12235d268a49af6a3c09c1" ON "dynamic_credential_entry" ("resolver_id") ;
CREATE UNIQUE INDEX "IDX_4c72ebdb265d1775bf61147af0" ON "chat_hub_tools" ("ownerId", "name") ;
COMMIT;
